How can I find out if a varible's value has been changed?

  1. What I want to achieve?

I want to learn how I can have a function that activates when a value of a variable (In my case a string value in replicated storage) is changed.

  1. What is the issue?

I could have a while loop that is only delayed with a wait() but that would cause unessary lag that I do not want.

  1. What solutions have you tried so far?

I have tried looking on the developer hub, but don’t know what to even search for. I looked under events of values, and couldn’t find it. Wait…seems like something like what I’m asking should be in there I should probably look better next time.

4 All the code that I have now

local status = game:WaitForChild("ReplicatedStorage").statusText

status.Oneventchangelol:connect(function()
	lol
end)

Instance values provide a changed event. StringValue | Roblox Creator Documentation

local status = game:WaitForChild("ReplicatedStorage").statusText

status.Changed:Connect(function()
	print(status.Value)
end)

Changed detects whenever any property of the object is changed.
GetPropertyChangedSignal only detects when one does.

local status = game:GetService("ReplicatedStorage"):WaitForChild("statusText")

status:GetPropertyChangedSignal("Value"):Connect(function()
    print(status.Value)
end)

If this was not what you wanted, please tell me

1 Like

That’s true for every instance except for ValueInstances. Since he’s using a StringValue, Changed will only fire when StringValue.Value is changed.

But they do still have Archivable, Name, and Parent

1 Like

Doesn’t matter. They overload Instance.Changed with their own Changed events.

From the docs I linked in an earlier reply:

2 Likes