i have a door that opens and closes Vertically but if a player is under the door, the door stops and is off track on future movements. anyone have a way to stop this?
here is my code
function click() if(script.Parent.Status.Value)=="Closed" then script.Parent.Status.Value="Opening" movements=58 speed=0.4 for i=1,movements do wait(0.01) script.Parent.Position=Vector3.new(script.Parent.Position.X,script.Parent.Position.Y+speed,script.Parent.Position.Z) end script.Parent.Status.Value="Open" elseif(script.Parent.Status.Value)=="Open" then script.Parent.Status.Value="Closeing" movements=58 speed=0.4 for i=1,movements do wait(0.01) script.Parent.Position=Vector3.new(script.Parent.Position.X,script.Parent.Position.Y-speed,script.Parent.Position.Z) end script.Parent.Status.Value="Closed" end end script.Parent.Control1.SurfaceGui.TextButton.MouseButton1Click:connect(click) script.Parent.Control2.SurfaceGui.TextButton.MouseButton1Click:connect(click)
The problem is that you're -not- using CFrames
function click() if(script.Parent.Status.Value)=="Closed" then script.Parent.Status.Value="Opening" movements=58 speed=0.4 for i=1,movements do wait(0.01) script.Parent.CFrame=script.Parent.CFrame + Vector3.new(0,speed,0); end script.Parent.Status.Value="Open" elseif(script.Parent.Status.Value)=="Open" then script.Parent.Status.Value="Closing" movements=58 speed=0.4 for i=1,movements do wait(0.01) script.Parent.CFrame = script.Parent.CFrame - Vector3.new(0,speed,0); end script.Parent.Status.Value="Closed" end end script.Parent.Control1.SurfaceGui.TextButton.MouseButton1Click:connect(click) script.Parent.Control2.SurfaceGui.TextButton.MouseButton1Click:connect(click)
Why?
Position and Size both check for collisions when they are set, whereas CFrames don't. Use CFrames for this sort of thing.