generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Having trouble with leaderstats

Previous Thread :: Next Thread 
177117 is not online. 177117
Joined: 17 May 2010
Total Posts: 1366
12 Mar 2017 03:22 PM
pastebin: /BfSeAMa4

The code is supposed to scan workspace for a certain model, and then pay the player depending on how many of the model there are. So if there are 5 zombies, it pays them 10 every few seconds, or if there are 2, it gives them less. etc. Not sure why it won't work.
Report Abuse
galio13 is not online. galio13
Joined: 20 Jul 2011
Total Posts: 842
12 Mar 2017 03:34 PM
You have a lowercased 'o'
Report Abuse
galio13 is not online. galio13
Joined: 20 Jul 2011
Total Posts: 842
12 Mar 2017 03:35 PM
You have NumberofThings, you'd have to do NumberOfThings.
Report Abuse
177117 is not online. 177117
Joined: 17 May 2010
Total Posts: 1366
12 Mar 2017 03:35 PM
Where? I can't find one that would make a difference.
Report Abuse
177117 is not online. 177117
Joined: 17 May 2010
Total Posts: 1366
12 Mar 2017 03:38 PM
Wow, good eye. But it still won't add the money to the leaderstat.
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
12 Mar 2017 04:02 PM
You're defining 'NumberOfThings' inside the local scope of function 'CheckForModels'. It won't be seen inside the scope of function 'AddCash'.


Report Abuse
177117 is not online. 177117
Joined: 17 May 2010
Total Posts: 1366
12 Mar 2017 04:04 PM
So how would I need to put "AddCash" into a separate script altogether? So that it keeps running independently of the other function? Only problem with this would be to redefine NumberOfThings all over again.
Report Abuse
galio13 is not online. galio13
Joined: 20 Jul 2011
Total Posts: 842
12 Mar 2017 04:05 PM
H^ was just the thing I was supposed to tell him.

So you take away "local" from the local numberofthings stuff so it'll get global scoped, or add it as a variable not in a function.
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
12 Mar 2017 04:08 PM
Forward-declare the variable and don't write to a localized 'NumberOfThings' in 'CheckForModels' because it'll overwrite the forward-declared one in the lower scope. Do something like this:

local NumberOfThings

local function CheckForModels()
NumberOfThings = 5
end

local function AddCash()
return NumberOfThings
end


Report Abuse
177117 is not online. 177117
Joined: 17 May 2010
Total Posts: 1366
12 Mar 2017 04:12 PM
Ok, so I moved the declaration of NumberOfThings to the beginning before the functions begin. I kept it local, but it still won't work.
Report Abuse
177117 is not online. 177117
Joined: 17 May 2010
Total Posts: 1366
12 Mar 2017 04:13 PM
Does this have to be in a localscript?
Report Abuse
galio13 is not online. galio13
Joined: 20 Jul 2011
Total Posts: 842
12 Mar 2017 04:15 PM
local NumberOfThings = 0

function CheckForModels()
local Player = game.Players.LocalPlayer
local Money = Player.leaderstats.money
local textlabel = script.Parent


NumberOfThings = 0

for num, part in pairs(workspace:GetChildren()) do
if part.Name == "SolarPanel" then
NumberOfThings = NumberOfThings + 1
textlabel.Text = tostring(NumberOfThings)
end
end
return NumberOfThings
end

function AddCash()
local NOT = CheckForModels()
if NOT >= 1 then
while wait(1) do
money.Value = money.Value + NOT * 100
end
end
end

workspace.ChildAdded:connect(function()
AddCash()
end)

workspace.ChildRemoved:connect(function()
AddCash()
end)


When life gives you lemonade. Give the lemonades back to life! What am I supposed to with lemons?
Report Abuse
177117 is not online. 177117
Joined: 17 May 2010
Total Posts: 1366
12 Mar 2017 04:22 PM
I still can't get it to work. The output isn't returning an error either. Thanks for the help though guys, I appreciate it.
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
12 Mar 2017 04:24 PM
OP, post your new script.


Report Abuse
177117 is not online. 177117
Joined: 17 May 2010
Total Posts: 1366
12 Mar 2017 04:26 PM
/vGEEN85L

I'm working off of the edits @Galio made
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
12 Mar 2017 04:28 PM
You're changing your code around. If you aren't using 'NumberOfThings' in another function then you don't need to forward declare it.


Report Abuse
177117 is not online. 177117
Joined: 17 May 2010
Total Posts: 1366
12 Mar 2017 04:31 PM
Alright, so I removed the local NumberOfThings that was declared before CheckForModels(), but it didn't make a difference.
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
12 Mar 2017 04:33 PM
Then the logic of your code is wrong and I can't help because I don't know how your game works.
To be honest I'd just handle it from the server because you shouldn't be checking leaderstats values locally anyway (assuming FilteringEnabled is on... otherwise it wouldn't make a difference).


Report Abuse
177117 is not online. 177117
Joined: 17 May 2010
Total Posts: 1366
12 Mar 2017 04:36 PM
Alright, thanks for the help though. FE is off btw. Its a single player game, so I don't really find the need for it yet.
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
12 Mar 2017 04:37 PM
The amount of players a game has shouldn't influence your decision of whether to make a game FilteringEnabled or not.


Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image