How can i detect when a IntValue changes?

Like, i know that i can use value.Changed but i don’t get how i should use it properly, my current script is this way:

local value = game.ReplicatedStorage.vals.Winner
 
value.Changed:Connect(function(winnerValue)
	local winnerValue = value.Value
    if value.Value ~= "" then
	script.Parent.Text = winnerValue
	end
end
)

The objective here is to detect when the Winner IntValue is not empty, then take it’s value to replace on a ScreenGui that i am using (when i use While True loop it works, i just want to learn how to use value.Changed properly)

Ah I was just working on this, but it seems you did it the way I did, which was a function so I couldn’t tell you how to do it different, but the ) from end needs to be together, and make sure to indent and organize so you don’t go crazy with scripts!

Do you mean string values?, i believe that int values are never == ""

Well, i am using IntValues and it works when i do it with While True Loops but not like this
(also i don’t know about this difference between String and Int values)

If you are talking about Int values which primarily hold integers, IntValue.Value == "" shouldn’t work with while loops either because int values will never be "" because they are not strings they’re numbers (integers) , so they will never empty unless you define empty as 0( the default value) . So this means that IntValue.Value ~= "" will always be true no matter what the int value is. Otherwise if you mean string values, that contain/hold strings then this if value.Value ~= "" then is “valid”.


Edit: Never mind i just realized that my previous answer (now edited post) shouldn’t actually be the reason why this inst working but just fyi winnerValue’s new value is passed through the event so local winnerValue = value.Value isn’t needed.

Oh my bad, i was mistaken, i was using StringValue all along, not IntValues xD but still, doesn’t work even if i do what you said in that last comment

hmm… i’m not sure why this wouldn’t work are there any errors in the output? and what does work and what doesn’t?

Also there is GetPropertyChangedSignal that you can use instead of changed.

4 Likes

Nothing at all on the output, and as i said, if i change this piece of code

value.Changed:Connect(function(winnerValue)

to this:

while true do

it works normally.

But using GetPropertyChangedSignal it worked now, thank you mate :slight_smile:

1 Like