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

How to Know If A value Has Changed?

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

✓ Accepted answer
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.

11 comments

0

thank you Xapelize, u are my true Savior ;-;

0

btw what tonumber do?

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!

0

oo

0

i try this but not working ;-; = local Added = tonumber(player:WaitForChild("leaderstats").Coin) - tonumber(cashbefore)

0

can you help me?

0

can you help me?

0

Are you sure the name is Coin? If it is, then the Coin value is probably nil?

0

Also, I think you can't make a math with variables using local

0

just print it,

0

ow ok

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