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

How can I make it that when a player has a certain amount of cash it resets to 0?

I've been trying for a while now and it isn't working :/

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)

6 comments

0

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?

0

Mind posting your code here so we can get a better understanding of what's going on?

0

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)

0

Where do you define the player?

0

I'm not sure I understand

0

Try using the updated code.

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.