-- So I attempted to make it so that it can't be glitched, and I sort of did but
-- If someone touches the part many times and walks away it will just open and close
-- forever
-- Also it doesn't always function the way I want it to (sometimes when you walk away,
-- the door stays open)
-- pls help me fix
local Opened = false
local Moving = false
local Host = script.Parent
local TouchPart = Host.TouchPart
local Players = game:GetService("Players")
local OpenedValues = {
[0.10] = false,
[-0.10] = true
}
local function MoveDoors(Direction)
local InitialOpened = Opened
while Moving do wait() end
if Opened == InitialOpened and Opened == OpenedValues[Direction] then
Moving = true
for _, Door in next, {Host.DoorLeft, Host.DoorRight} do
local NewDirection = Vector3.new(Door.Name == "DoorLeft" and Direction or -Direction, 0, 0)
spawn(function()
for i = 1, 5.1, math.abs(Direction) do
wait()
Door.Base.CFrame = Door.Base.CFrame-NewDirection
Door.End.CFrame = Door.End.CFrame-NewDirection
end
Moving = false
end)
end
end
end
TouchPart.Touched:connect(function(Hit)
if not Opened and Players:GetPlayerFromCharacter(Hit.Parent) then
MoveDoors(0.10)
Opened = true
end
end)
TouchPart.TouchEnded:connect(function(Hit)
if Opened and Players:GetPlayerFromCharacter(Hit.Parent) then
for _, Part in next, TouchPart:GetTouchingParts() do
if Players:GetPlayerFromCharacter(Part.Parent) then
return
end
end
MoveDoors(-0.10)
Opened = false
end
end) |