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

How would I check if a number value got updated?

Asked by 6 years ago
1local Number = script.Parent.Number
2local Player = game.Players.LocalPlayer:GetFullName()
3local Max = script.Parent.Max.Value
4local PlayerCrops = game.Workspace.CropsInBackpack.Value
5 
6Number.Text = (PlayerCrops.. " / ".. Max)

So, I want to check if a number value got updated. How would I do that? For example, If say a number value of 1 got updated to like a value of 3. How would I check for that? So I can update my Gui everytime the value gets changed.

2 answers

Log in to vote
0
Answered by 6 years ago

Hi there! What you could do is store an IntValue in a script, and then write something like this in another script, if I am correct:

1script.Number.Value.Changed:Connect(function()
2    --stuff here :D
3end)

If this doesn't work, let me know!

0
Correction: "script" refers to the script with the IntValue, not the script that checks if the number value is updated. SnazzySpider67 53 — 6y
0
(IntValue.Value.Changed) will error. You have to do (IntValue.Changed) zyrun 168 — 6y
0
Thanks to your answer I found out about the Changed event, thank you so much! HarmonicPower 14 — 6y
0
Ah, thanks! Normally I would've caught that! SnazzySpider67 53 — 6y
Ad
Log in to vote
0
Answered by
zyrun 168
6 years ago

For if your number is actually a NumberValue object, not a variable:

1local Number = script.Parent.Number -- The gui that will change
2local NumberValueThatWillChange = game.Workspace.CropsInBackpack -- Hopfully this is the number that changes
3 
4NumberValueThatWillChange.Changed:Connect(function(Property)
5    if Property = "Value" then -- Make sure that the value is changing, not the name or something
6    Number.Text = tostring(NumberValueThatWillChange) -- tostring makes sure of no errors in that area
7end)

For if your number is a variable:

01local Number = script.Parent.Number -- The gui that will change
02local NumberValueThatWillChange = 69 -- 69, Nice
03local PastNumberValue = NumberValueThatWillChange -- To check for updates
04 
05while true do
06    if PastNumberValue ~= NumberValueThatWillChange then
07        PastNumberValue = NumberValueThatWillChange
08        Number.Text = tostring(NumberValueThatWillChange) -- tostring makes sure of no errors in that area     
09    end
10    wait(.1)
11end
0
Ah. I was unaware of that.I did mean to put the second '=' on line 5. Thank you for the correction though. The while loop was for the local variable, not an IntValue. zyrun 168 — 6y

Answer this question