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

I have a problem with a script detecting a change of a local variable.?

Asked by
igric 29
6 years ago
-- This is an example script located in a Part.
local something = workspace.IntValue.Value

-- I eventually set my intValue form 1 to 2 with another script

script.Parent.Touched:Connect(function()
    print(something) -- This would print 1
end)

Is there any way for script to check if variable changed it's value?

2 answers

Log in to vote
0
Answered by 6 years ago

There's an event you can use called "Changed". Here's an example of how it works :

local something = workspace.IntValue

something.Changed:Connect(function(value) --The value is the value that changed
    print(value)
end)

The script prints the new value every time the IntValue changes. So yeah. :P

Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

declare the variable inside the function, the variable is not going to automatically update if the the value changes, lets say you declare a variable called pos

local pos = script.Parent.Position

its going to put its position of where its at in that point in time, so if you put it into the function, it'll declare it everytime its stepped on

Answer this question