How would I make this script run, when a value is changed instead of the script being something like:
while true do
wait()
if value == "1" then
--script
end
end
and does it even affect the game if scripts are like that?
How would I make this script run, when a value is changed instead of the script being something like:
while true do
wait()
if value == "1" then
--script
end
end
and does it even affect the game if scripts are like that?
:GetPropertyChangedSignal() is what you’re looking for.
Example:
game.Workspace.Bool:GetPropertyChangedSignal("Value"):Connect(function()
if game.Workspace.Bool.Value == 1 then
-- script
end
end)
Quick nitpick: BoolValues (and all of the other XyzValue objects) have a Changed property that accomplishes this in a slightly simpler manner:
workspace.Bool.Changed:Connect(function(state)
print(state)
end)
The “Changed” event also fires when any property such as the name is changed. So his way would be more proper. (unless you arent changing the name it should be just fine)
So it basically saves some lines but has the same effect?
Yeah, the only difference between them is that BoolValue.Changed gets fired with the new value and BoolValue:GetPropertyChangedSignal(“Value”) doesn’t.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.