I've been trying for a while now and it isn't working :/
✓ ANSWER ACCEPTED
How can I make it that when a player has a certain amount of cash it resets to 0?
2 answers
✓ Accepted answer
Hey Michael, we can do this by using a .changed function. Instead of having an infinite loop, we can just simply check when a variable changes. Make sure you define the player and their values correctly.
We'll use these made-up variables as an example:
local player = game.Players.LocalPlayer
local character = player.CharacterAdded:wait() -- Wait for Player
local p = Instance.new("NumberValue")
p.Name = "cash"
p.Parent = player
local cash = player:WaitForChild("cash")
local limit = 5 -- Change this to whatever you want the max value to be.
cash.Changed:connect(function(NewValue)
print(cash.Value)
if cash.Value >= limit then -- If the cash if equal to or greater than 5, then set it to 0.
cash.Value = 0
end
end)
while true do
local check = game.Players.Playername
local check1 = check:FindFirstChild("leaderstats")
local check3 = check1:WaitForChild("Cash or what ever you call this")
if check then
if check2 then
if check3 then
if check1.Cash == yourammount then
Cash.Value 0
end
end
end
end
wait(1)
end
This should work
5 comments
0
Thank you!
0
So it worked.
0
Well, no. I tried it and it's not working.
0
OK wait
0
Okay
This discussion is preserved as it was. New answers, comments, and votes are closed.

6 comments
It isn't working D: Maybe it's something on my part. I pasted the code in a script located in ServerScriptService. Am I doing something wrong?
Mind posting your code here so we can get a better understanding of what's going on?
local cash = plr.leaderstats.Cash.Value local limit = 100 -- Change this to whatever you want the max value to be. cash.Changed:connect(function(Value) print'cash' if cash >= limit then -- If the cash if equal to or greater than 5, then set it to 0. cash = 0 end end)
Where do you define the player?
I'm not sure I understand
Try using the updated code.