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

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

Asked by 6 years ago
Edited 6 years ago

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.

0
can you specify creeperhunter76 554 — 6y
0
I think I specified enough. PyccknnXakep 1225 — 6y

2 answers

Log in to vote
2
Answered by
XAXA 1569 Moderation Voter
6 years ago
Edited 6 years ago

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!"
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. PyccknnXakep 1225 — 6y
0
Aww, there isint an actual way to see if a variable been changed :( hiimgoodpack 2009 — 6y
Ad
Log in to vote
1
Answered by 6 years ago

BoolValue.Changed:connect(function(NewValue) print(NewValue) end)

http://wiki.roblox.com/index.php?title=API:Class/BoolValue/Changed

Answer this question