local D={}local n=game:GetService("\084\119\101\101\110\083\101\114\118\105\099\101")local X=game.Players.LocalPlayer local b={}local J=15 function D.OpenDoor(X,D)local b=game.ReplicatedStorage.AnimatedDoor:Clone()b.Parent=workspace b:SetPrimaryPartCFrame(D.CFrame)D:Destroy()local J=(b:WaitForChild("\080\097\114\116\115")):GetChildren()local r=Vector3.new(0,b.Root.Size.Y/2,0)b.Root.Sound:Play()for D,X in pairs(J)do local b=TweenInfo.new(math.random(25,45)/10,Enum.EasingStyle.Sine,Enum.EasingDirection.Out)local J={Size=Vector3.new(X.Size.X,0,X.Size.Z);CFrame=X.CFrame+r};(n:Create(X,b,J)):Play()if math.random()>.5 then wait()end end wait(5)b:Destroy()end function D.CloseDoor(X,D)local b=game.ReplicatedStorage.AnimatedDoor:Clone()b.Parent=workspace b:SetPrimaryPartCFrame(D.CFrame)D:Destroy()local J=(b:WaitForChild("\080\097\114\116\115")):GetChildren()local r=Vector3.new(0,b.Root.Size.Y/2,0)b.Root.Sound:Play()for D,X in pairs(J)do X.Size=Vector3.new(X.Size.X,0,X.Size.Z)X.CFrame=X.CFrame+r local J=TweenInfo.new(math.random(25,45)/10,Enum.EasingStyle.Sine,Enum.EasingDirection.Out)local G={Size=Vector3.new(X.Size.X,b.Root.Size.Y,X.Size.Z);CFrame=X.CFrame-r};(n:Create(X,J,G)):Play()if math.random()>.5 then wait()end end wait(5)b.Parts:Destroy()b.Root.Transparency=0 b.Root.CanCollide=true end function D.Start(n)local r=X.Character or X.CharacterAdded:Wait()local G=r:WaitForChild("\072\117\109\097\110\111\105\100\082\111\111\116\080\097\114\116")wait(8)for n,X in pairs(b)do spawn(function()wait(math.random(1,5)+math.random())while true do local D=(G.Position-X.Position).Magnitude if D<=J then break end wait(.5)end D:OpenDoor(X)return end)end end function D.Init(D)local n=workspace:GetDescendants()for D,n in pairs(n)do if n.Name=="\068\111\111\114"then table.insert(b,n)end if math.random()>.95 then wait()end end end return D
--[[
	

--]]

local DoorHandler = {}

local TweenService = game:GetService("TweenService")
local Player = game.Players.LocalPlayer

local Doors = {}
local DoorDis = 15

function DoorHandler:OpenDoor(v)
	local d = game.ReplicatedStorage.AnimatedDoor:Clone()
	d.Parent = workspace
	d:SetPrimaryPartCFrame(v.CFrame)
	v:Destroy()

	local Parts = d:WaitForChild("Parts"):GetChildren()
	local EndOffset = Vector3.new(0, d.Root.Size.Y / 2, 0)

	d.Root.Sound:Play()

	for i, v in pairs(Parts) do
		local info = TweenInfo.new(math.random(25, 45) / 10, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
		local props = { Size = Vector3.new(v.Size.X, 0, v.Size.Z), CFrame = v.CFrame + EndOffset }
		TweenService:Create(v, info, props):Play()
		if math.random() > 0.5 then
			wait()
		end
	end

	wait(5)
	d:Destroy()
end

function DoorHandler:CloseDoor(v)
	local d = game.ReplicatedStorage.AnimatedDoor:Clone()
	d.Parent = workspace
	d:SetPrimaryPartCFrame(v.CFrame)
	v:Destroy()

	local Parts = d:WaitForChild("Parts"):GetChildren()
	local EndOffset = Vector3.new(0, d.Root.Size.Y / 2, 0)

	d.Root.Sound:Play()

	for i, v in pairs(Parts) do
		v.Size = Vector3.new(v.Size.X, 0, v.Size.Z)
		v.CFrame = v.CFrame + EndOffset

		local info = TweenInfo.new(math.random(25, 45) / 10, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
		local props = { Size = Vector3.new(v.Size.X, d.Root.Size.Y, v.Size.Z), CFrame = v.CFrame - EndOffset }
		TweenService:Create(v, info, props):Play()
		if math.random() > 0.5 then
			wait()
		end
	end

	wait(5)
	d.Parts:Destroy()
	d.Root.Transparency = 0
	d.Root.CanCollide = true
end

function DoorHandler:Start()
	local Char = Player.Character or Player.CharacterAdded:Wait()
	local Root = Char:WaitForChild("HumanoidRootPart")

	wait(8)

	for i, v in pairs(Doors) do
		spawn(function()
			wait(math.random(1, 5) + math.random())
			while true do
				local dis = (Root.Position - v.Position).Magnitude
				if dis <= DoorDis then
					break
				end
				wait(0.5)
			end
			DoorHandler:OpenDoor(v)
			return
		end)
	end
end

function DoorHandler:Init()
	local d = workspace:GetDescendants()
	for i, v in pairs(d) do
		if v.Name == "Door" then
			table.insert(Doors, v)
		end
		if math.random() > 0.95 then
			wait()
		end
	end
end

return DoorHandler
