For some reason, if the player walks in the door while it is moving then the door goes over the player. How can I make it so the door does not go over the player? I think this is just a coding error.
OpenDet = script.Parent.Open
CoolDet = script.Parent.Cooldown
OpIfDet = script.Parent.DidOpenIf
local function onMouseClick(player)
if CoolDet.Value == false and game.Workspace:FindFirstChild(player.Name):FindFirstChild("JailKeys") ~= nil then --Check if player is holding keys plus debounce
CoolDet.Value = true
local x = script.Parent.Position.X
local y = script.Parent.PositionData.OrgY.Value
local z = script.Parent.Position.Z
if OpenDet.Value == false then --If closed
OpenDet.Value = true
repeat
wait(0.1)
x = x - 0.1
script.Parent.Position = Vector3.new(x, y, z)
until script.Parent.Position.X == script.Parent.PositionData.NewX.Value
repeat
wait(0.1)
z = z - 0.5
script.Parent.Position = Vector3.new(x, y, z)
until script.Parent.Position.Z == script.Parent.PositionData.NewZ.Value
OpIfDet.Value = true --So open sequence does not occor if door was clicked on twice or more
end
if OpenDet.Value == true and OpIfDet.Value == false then --If open
OpenDet.Value = false
repeat
wait(0.1)
z = z + 0.5
script.Parent.Position = Vector3.new(x, y, z)
until script.Parent.Position.Z == script.Parent.PositionData.OrgZ.Value
repeat
wait(0.1)
x = x + 0.1
script.Parent.Position = Vector3.new(x, y, z)
until script.Parent.Position.X == script.Parent.PositionData.OrgX.Value
--Not nessessary to put a OpIfDet.Value = true as this is the last if statement.
end
CoolDet.Value = false --End
OpIfDet.Value = false
end
end
script.Parent.Click.MouseClick:connect(onMouseClick)
