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

Is there a way to detect if a variable has changed?

I am not talking about BoolValues or any type of Value, only variables.

I want to know if it's possible to detect if a variable has been set to true/false, kind of like the Changed event. But I recall trying to use the Changed event on a variable before, and it didn't work. Just a quick question, any help appreciated.

2 comments

0

can you specify

0

I think I specified enough.

2 answers

✓ Accepted answer

Using plain Lua variables? No, there isn't. You probably used the .Changed event on a BoolValue without knowing.

You can, however, use Roblox built-in BoolValues, NumberValues, StringValues (and other values) in your scripts and listen to their .Changed events. This is a common practice:

local str = Instance.new("StringValue")
val.Changed:Connect(function(newStr)
	print(newStr)
end)

str.Value = "Hello, World!"

2 comments

0

I knew about using the Changed event on a BoolValue, I was just wondering if I could do it with a variable. But thanks anyway.

0

Aww, there isint an actual way to see if a variable been changed :(

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