Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

how do i stop players from blocking this CFrame operation?

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)

2 comments

0

sorry the CFrame operations are cut, if you need the rest comment and il post it

0

Maybe make it so that a player can't go under the door?

1 answer

✓ Accepted answer

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.

2 comments

0

Thanks,just noticed that the close code did not have a - but apart from that it works fine

0

Oh, yeah. Edited to match.

This discussion is preserved as it was. New answers, comments, and votes are closed.