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

How to Know If A value Has Changed?

Asked by 3 years ago

So here the example;

Cash = 10,

Cash get added with some value,

Now Cash = 100,

Question:

  1. How to know when the Cash value changed?

  2. How to know how much Value that has been added to Cash?

Thank's for Reading!

1 answer

Log in to vote
1
Answered by
Xapelize 2658 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago
cashbefore = game.Players.LocalPlayer.leaderstats.Cash

game.Players.LocalPlayer.leaderstats.Cash.Changed:Connect(function() -- if a property is changed on the value
    print(tonumber(game.Players.LocalPlayer.leaderstats.Cash) - tonumber(cashbefore)) -- prints the cash how many it added
    cashbefore = game.Players.LocalPlayer.leaderstats.Cash -- updates the cash currently
end)

Mistake some people will do: Value.Value.Changed, Value:Changed or any kind.

0
thank you Xapelize, u are my true Savior ;-; The_Saver31 260 — 3y
0
btw what tonumber do? The_Saver31 260 — 3y
0
Change the string to number! Like a string value's value is a string, so you can convert it to numbers if you type numbers inside! Xapelize 2658 — 3y
0
oo The_Saver31 260 — 3y
View all comments (7 more)
0
i try this but not working ;-; = local Added = tonumber(player:WaitForChild("leaderstats").Coin) - tonumber(cashbefore) The_Saver31 260 — 3y
0
can you help me? The_Saver31 260 — 3y
0
can you help me? The_Saver31 260 — 3y
0
Are you sure the name is Coin? If it is, then the Coin value is probably nil? Xapelize 2658 — 3y
0
Also, I think you can't make a math with variables using local Xapelize 2658 — 3y
0
just print it, Xapelize 2658 — 3y
0
ow ok The_Saver31 260 — 3y
Ad

Answer this question