Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago

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

Log in to vote
-1
Answered by 7 years ago

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)
0
Is there a certain place I should put this script or can I just place it in ServerScriptService? Michael_TheCreator 166 — 7y
0
Just make sure it's in a LocalScript. Tradesmark 65 — 7y
Ad

Answer this question