Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

how do i stop players from blocking this CFrame operation?

Asked by
lukeb50 631 Moderation Voter
9 years ago

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)
0
sorry the CFrame operations are cut, if you need the rest comment and il post it lukeb50 631 — 9y
0
Maybe make it so that a player can't go under the door? ScriptFusion 210 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

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.

0
Thanks,just noticed that the close code did not have a - but apart from that it works fine lukeb50 631 — 9y
0
Oh, yeah. Edited to match. User#6546 35 — 9y
Ad

Answer this question