Everything here is working properly, but when I click a second time, it wont execute.
I’m not quite sure what I’m missing here, help would be much appreciated! Thanks.
local speed = 4
local increment = 0
local direction = false -- false = left, true = right
local hm = 0
script.Parent.ClickDetector.MouseClick:Connect(function()
if direction then
increment = 2
else
increment = -2
end
for i = 1,50 do
wait()
script.Parent.Orientation = script.Parent.Orientation + Vector3.new(0,0,increment) * speed
hm = i
end
if hm == 50 then
direction = not direction
end
end)
Close, but not quite yet. Put the for loop one indent more.
Your edit did help me find your issue, which is:
You are setting direction to true in the last if statement.
The for loop only runs in the part of the first if statement that runs only if direction is false.
I think it may be your intention to end the first if statement before it goes to the for loop:
if direction then
increment = 2
else
increment = -2
end
Make sure to remove the end second from the bottom, and put the for loop and the last if statement back one indent.