Automatic Door

local model = script.Parent


local trigger_in = model.Trigger_In

local trigger_out = model.Trigger_Out


local left = model.MainL

local right = model.MainR


local activated = false


local TweenService = game:GetService("TweenService")


local tweenInfo = TweenInfo.new(

model.Speed.Value, --Time

Enum.EasingStyle.Quart, --Easing Style

Enum.EasingDirection.Out, --EasingDirection

0, --Repeat Count

true, --Reverse

0 --DelayTime

)


local function open(otherPart)

local player = game.Players:FindFirstChild(otherPart.Parent.Name)

if player and not activated then

activated = true

model["Door"]:Play()

local tweenL = TweenService:Create(left, tweenInfo, {Position = model.TargetL.Position})

local tweenR = TweenService:Create(right, tweenInfo, {Position = model.TargetR.Position})

tweenL:Play()

tweenR:Play()

tweenR.Completed:Wait()

activated = false

end

end


trigger_in.Touched:Connect(open)

trigger_out.Touched:Connect(open)