I made this script, everything looks fine but it don't react when the value is true...
if script.Parent.Parent.Bool == true then for i = 1,70 do script.Parent.Position.Z = script.Parent.Position - Vector3.new(0,0,0.05) wait(0.001) end wait(5) for i = 1,70 do script.Parent.Position.Z = script.Parent.Position + Vector3.new(0,0,0.05) end end
I changed the default name of the BoolValue because the game don't understand when i call Value.Value idk if it can cause problems.
I am very confused about Bolean value right now, I tough it was easy to use lol! Thank you in advance !
This is because a BoolValue has a property called Value which is where you can read/write the bool from
if script.Parent.Parent.Bool.Value == true then for i = 1,70 do script.Parent.Position.Z = script.Parent.Position - Vector3.new(0,0,0.05) wait(0.001) end wait(5) for i = 1,70 do script.Parent.Position.Z = script.Parent.Position + Vector3.new(0,0,0.05) end end
you need to register an event listener to to the Bool value
because if you just write the following code, then when the game starts it will immediately run the code, only once..
if script.Parent.Parent.Bool == true then for i = 1,70 do script.Parent.Position.Z = script.Parent.Position - Vector3.new(0,0,0.05) wait(0.001) end wait(5) for i = 1,70 do script.Parent.Position.Z = script.Parent.Position + Vector3.new(0,0,0.05) end end
but if you register an event handler to the bool value then the code will always run everytime that an event occurs;
the event you can use is called Changed
. and here is how you can use it..
local bool = game.etc.ect.Bool -- change to directory of the bool value bool.Changed:Connect(function() if script.Parent.Parent.Bool == true then for i = 1,70 do script.Parent.Position.Z = script.Parent.Position - Vector3.new(0,0,0.05) wait(0.001) end wait(5) for i = 1,70 do script.Parent.Position.Z = script.Parent.Position + Vector3.new(0,0,0.05) end end end)
note: Changed
listens for when any changes occur on the subject object;
you can use GetPropertyChangedSignal
to listens for only a single property
like so:
local bool = game.etc.ect.Bool -- change to directory of the bool value bool:GetPropertyChangedSignal("Value"):Connect(function() if script.Parent.Parent.Bool == true then for i = 1,70 do script.Parent.Position.Z = script.Parent.Position - Vector3.new(0,0,0.05) wait(0.001) end wait(5) for i = 1,70 do script.Parent.Position.Z = script.Parent.Position + Vector3.new(0,0,0.05) end end end)
the above code only listens for when the Value
Property changes~
you can find out more about events on:
thank you!