local z=game:GetService("\084\119\101\101\110\083\101\114\118\105\099\101")local R=script.Parent local m=R.Trigger local C=R.TargetL_Closed local q=R.TargetR_Closed local N=R.DoorTrigger.Value local J=TweenInfo.new(R.Speed.Value,Enum.EasingStyle.Quart,Enum.EasingDirection.InOut,0,false,0)local T={Closed=1;Opening=2;Open=3;Closing=4}local M=T.Closed local v={}local O=z:Create(C,J,{CFrame=R.TargetL_Open.CFrame})local b=z:Create(q,J,{CFrame=R.TargetR_Open.CFrame})local V=z:Create(C,J,{CFrame=R.TargetL_Closed.CFrame})local n=z:Create(q,J,{CFrame=R.TargetR_Closed.CFrame})local function s()N.CanTouch=false print("\070\097\108\115\101")M=T.Opening R.Door:Play()O:Play()b:Play()wait(7)N.CanTouch=true print("\084\114\117\101")end local function U()M=T.Closing V:Play()n:Play()end local function Q(z)if next(v)==nil then U()else M=T.Open end end local function o(z)if next(v)~=nil then s()else M=T.Closed end end O.Completed:Connect(Q)V.Completed:Connect(o)local function Z(z)if z.Name=="\072\117\109\097\110\111\105\100\082\111\111\116\080\097\114\116"then local R=game.Players:FindFirstChild(z.Parent.Name)if R then v[R]=1 if M==T.Closed then s()end end end end


local TweenService = game:GetService("TweenService")

local model = script.Parent

local trigger = model.Trigger

local left = model.TargetL_Closed
local right = model.TargetR_Closed

local doorTrigger = model.DoorTrigger.Value

local tweenInfo = TweenInfo.new (
	model.Speed.Value, --Time/Speed of Door Tween
	Enum.EasingStyle.Quart,  --Easing Style
	Enum.EasingDirection.InOut, --EasingDirection
	0, --Repeat Count
	false, --Reverse true
	0 --Delay
)

local DoorState = {
	["Closed"] = 1,
	["Opening"] = 2,
	["Open"] = 3,
	["Closing"] = 4,
}

local doorState = DoorState.Closed 
local playersNear = {}

local tweenL = TweenService:Create(left, tweenInfo, {CFrame = model.TargetL_Open.CFrame})
local tweenR = TweenService:Create(right, tweenInfo, {CFrame = model.TargetR_Open.CFrame})

local tweenLClose = TweenService:Create(left, tweenInfo, {CFrame = model.TargetL_Closed.CFrame})
local tweenRClose = TweenService:Create(right, tweenInfo, {CFrame = model.TargetR_Closed.CFrame})

local function StartOpening()
	doorTrigger.CanTouch = false
	print("False")
	doorState = DoorState.Opening
	model["Door"]:Play()

	tweenL:Play()
	tweenR:Play()
	wait(7)
	doorTrigger.CanTouch = true
	print("True")
end

local function StartClosing()
	doorState = DoorState.Closing
	--model["Door"]:Play()

	tweenLClose:Play()
	tweenRClose:Play()
end

local function tweenOpenCompleted(playbackState)
	if(next(playersNear) == nil) then
		StartClosing()
	else
		doorState = DoorState.Open
	end
end

local function tweenCloseCompleted(playbackState)
	if(next(playersNear) ~= nil) then
		StartOpening()
	else
		doorState = DoorState.Closed
	end
end

tweenL.Completed:Connect(tweenOpenCompleted)
tweenLClose.Completed:Connect(tweenCloseCompleted)

local function touched(otherPart)
	if(otherPart.Name == "HumanoidRootPart" ) then
		local player = game.Players:FindFirstChild(otherPart.Parent.Name)
		if(player) then
			--print("touch")
			playersNear[player] = 1
			if(doorState == DoorState.Closed) then
				StartOpening()
			end
		end
	end
end
