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




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
