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

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

Asked by 7 years ago

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

2 answers

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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)
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? Michael_TheCreator 166 — 7y
0
Mind posting your code here so we can get a better understanding of what's going on? Tradesmark 65 — 7y
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) Michael_TheCreator 166 — 7y
0
Where do you define the player? Tradesmark 65 — 7y
View all comments (2 more)
0
I'm not sure I understand Michael_TheCreator 166 — 7y
0
Try using the updated code. Tradesmark 65 — 7y
Ad
Log in to vote
1
Answered by 7 years ago
Edited 7 years ago
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

0
Thank you! Michael_TheCreator 166 — 7y
0
So it worked. johndeer2233 439 — 7y
0
Well, no. I tried it and it's not working. Michael_TheCreator 166 — 7y
0
OK wait johndeer2233 439 — 7y
0
Okay Michael_TheCreator 166 — 7y

Answer this question