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

How would I check if a number value got updated?

local Number = script.Parent.Number
local Player = game.Players.LocalPlayer:GetFullName()
local Max = script.Parent.Max.Value
local PlayerCrops = game.Workspace.CropsInBackpack.Value

Number.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

✓ Accepted answer

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:

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

If this doesn't work, let me know!

4 comments

0

Correction: "script" refers to the script with the IntValue, not the script that checks if the number value is updated.

0

(IntValue.Value.Changed) will error. You have to do (IntValue.Changed)

0

Thanks to your answer I found out about the Changed event, thank you so much!

0

Ah, thanks! Normally I would've caught that!

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

local Number = script.Parent.Number -- The gui that will change
local NumberValueThatWillChange = game.Workspace.CropsInBackpack -- Hopfully this is the number that changes

NumberValueThatWillChange.Changed:Connect(function(Property)
	if Property = "Value" then -- Make sure that the value is changing, not the name or something
	Number.Text = tostring(NumberValueThatWillChange) -- tostring makes sure of no errors in that area
end)

For if your number is a variable:

local Number = script.Parent.Number -- The gui that will change
local NumberValueThatWillChange = 69 -- 69, Nice
local PastNumberValue = NumberValueThatWillChange -- To check for updates

while true do
	if PastNumberValue ~= NumberValueThatWillChange then
		PastNumberValue = NumberValueThatWillChange
		Number.Text = tostring(NumberValueThatWillChange) -- tostring makes sure of no errors in that area 		
	end
	wait(.1)
end

1 comment

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.

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