Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Cash limit script isn't working, I have no idea why. Can anyone help me fix it?

So, I inserted this code (code will be pasted at the bottom) into a local script and placed that script in StarterPlayerScripts. I have no idea why it isn't working. This code is supposed to reset your cash to 0 if you have 100 or more.

local cash = script.Parent.Parent.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)

1 answer

✓ Accepted answer

Try this.

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)

2 comments

0

Is there a certain place I should put this script or can I just place it in ServerScriptService?

0

Just make sure it's in a LocalScript.

This discussion is preserved as it was. New answers, comments, and votes are closed.