I am trying to make a moving platform in my game.
It looks like this:
But I have a problem I cant figure out
So for some reason for the 1st loop, the detection works. But then in the second loop, the if statement is completely ignored.
Here is my code:
script.Parent.Touched:connect(function()
local y = 4.5
script.Parent.Color = Color3.new(0, 0, 0)
script.Parent.CanTouch = false
script.Parent.Transparency = 0.2
script.Parent.CanCollide = false
while true do
wait(0.1)
script.Parent.Parent.Platform_1.Position = Vector3.new(-21, y, -223)
y += 1
--check if the platform is there
if script.Parent.Parent.Platform_1.Position == Vector3.new(-21, 37.5, -223) then
wait(5)
y= 37.5
while true do
-- second loop
wait(0.1)
if script.Parent.Parent.Platform_1.Position == Vector3.new(-24, 4.5, -223) then
--Does not work (ignored if statement
print('stop')
break
else
--Only this runs
print('going down')
y -= 1
script.Parent.Parent.Platform_1.Position = Vector3.new(-21, y, -223)
end
end
end
end
end)
I have tried putting the movement code that makes it go down somewhere else and recently added the else statement, but it still does not work. I checked the position to make sure the position is exact also as the one the script is checking, but it still does not work.
Can anyone help?