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
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
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:
Youtube
Roblox API reference
thank you!
3 comments
A bolean value is true or false isn't it? so if i set the Bool.Value to true this chunck of script should run shouldn't it?
@Louix27626 thats correct!
So, idk why it doesn't work :S