I've been trying for a while now and it isn't working :/
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