You define MoneyDebounce locally inside the of the while loop. That value doesn’t exist outside the scope of the while loop. If you move the local MoneyDebounce = 0 to be outside of the while loop, it should continue to increment.
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(Player)
local leaderstats = Instance.new("IntValue")
leaderstats.Parent = Player
leaderstats.Name = "leaderstats"
local Time = Instance.new("IntValue")
Time.Parent = leaderstats
Time.Name = "Time Played"
local Money = Instance.new("IntValue")
Money.Parent = leaderstats
Money.Name = "Cash"
Money.Value = 0
local Timer = 0
task.spawn(function()
while task.wait(1) do
Time.Value += 1
Timer += 1
print(Timer)
if Timer == 60 then
Money.Value += 10
end
end
end)
end)
A few issues, you’re using the deprecated connection method “:connect()” instead of the current version “:Connect()” which should be used for any new work, you’re setting the parent parameter when calling Instance.new() which is strongly advised against, more info regarding that here.
You’re using “stats” as a variable name (I’ve opted to use “leaderstats” instead) which conflicts with a reserved global in Roblox Lua (this is why it appears as red text), its purpose is to get the stats service.
Statsstats ( )
Returns the Stats service.
It is preferred that developers use ServiceProvider:GetService to retrieve it instead.
and as previously mentioned you’re declaring “MoneyDebounce” locally inside the while loop and assigning to it a value of 0 everytime the cycle performs a single loop/pass/round which means that when its value is incremented by 1 it’ll just get set to 1 before being reset back to 0.
I also believe you made an issue with the cash giving part, I assume you’re trying to give 10 cash per 60 seconds of in-game time which elapse but in your script the cash value is just set to 10 instead of being incremented by 10, so I’ve fixed this too.
Finally, instead of doing x = x + n to increase the value stored inside some variable (example named x) by some value (example named n) you can just use x += n to perform the same arithmetic calculation, this will work with the other arithmetic operators too like /, +, * etc.