local y={}local P=game:GetService("\084\119\101\101\110\083\101\114\118\105\099\101")local X=TweenInfo.new(1,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut)local C={}function y.OPEN(y)if not y then return end local X=y:WaitForChild("\069\102\102\101\099\116\115")local D=X:GetChildren()for y,P in pairs(D)do if P.Name=="\085\110\108\111\099\107"then P:Play()continue end if P:IsA("\066\101\097\109")or P:IsA("\080\111\105\110\116\076\105\103\104\116")or P:IsA("\080\097\114\116\105\099\108\101\069\109\105\116\116\101\114")then P.Enabled=true end end local U=y:GetChildren()for y,X in pairs(U)do if not X:IsA("\077\111\100\101\108")then continue end C[X]=X.PrimaryPart.CFrame local D=(X.PrimaryPart.CFrame+Vector3.new(math.random(-1,1),3,math.random(-1,1)))*CFrame.Angles(math.rad(math.random(1,360)),math.rad(math.random(1,360)),math.rad(math.random(1,360)))local U=TweenInfo.new(1,Enum.EasingStyle.Quint,Enum.EasingDirection.In);(P:Create(X.PrimaryPart,U,{CFrame=D})):Play()end wait(1)for y,X in pairs(U)do if not X:IsA("\077\111\100\101\108")then continue end local C=(X.PrimaryPart.CFrame+Vector3.new(math.random(-20,20),50,math.random(-20,20)))*CFrame.Angles(math.rad(math.random(1,360)),math.rad(math.random(1,360)),math.rad(math.random(1,360)))local D=TweenInfo.new(2,Enum.EasingStyle.Linear)local U=P:Create(X.PrimaryPart,D,{CFrame=C})U:Play()local m=nil m=U.Completed:Connect(function()m:Disconnect()X.PrimaryPart.CFrame=X.PrimaryPart.CFrame-Vector3.new(0,300,0)end)end wait(.5)for y,P in pairs(D)do if P:IsA("\066\101\097\109")or P:IsA("\080\111\105\110\116\076\105\103\104\116")or P:IsA("\080\097\114\116\105\099\108\101\069\109\105\116\116\101\114")then P.Enabled=false end end end function y.CLOSE(y)if not y then return end local P=y:GetChildren()for y,P in pairs(P)do if P:IsA("\077\111\100\101\108")then P.PrimaryPart.CFrame=C[P]or P.PrimaryPart.CFrame end end end return y


local DoorFX = {}

local tweenService = game:GetService("TweenService")

local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)



local InitialModelCFrames = {}

function DoorFX.OPEN(door)
	if not door then return end
	
	local EffectsBrick = door:WaitForChild("Effects")
	local Effects = EffectsBrick:GetChildren()

	for _, Item in pairs (Effects) do
		if Item.Name == "Unlock" then Item:Play() continue end
		if Item:IsA("Beam") or Item:IsA("PointLight") or Item:IsA("ParticleEmitter") then
			Item.Enabled = true
		end
	end

	local Components = door:GetChildren()
	for _, Component in pairs (Components) do
		if not Component:IsA("Model") then continue end

		InitialModelCFrames[Component] = Component.PrimaryPart.CFrame

		local CFrameGoal = (Component.PrimaryPart.CFrame + Vector3.new(math.random(-1,1),3,math.random(-1,1))) 
			* CFrame.Angles(math.rad(math.random(1,360)), math.rad(math.random(1,360)), math.rad(math.random(1,360)))
	
		local TweenInf = TweenInfo.new(1, Enum.EasingStyle.Quint, Enum.EasingDirection.In)
		tweenService:Create(Component.PrimaryPart, TweenInf, {CFrame = CFrameGoal}):Play()
	end

	wait(1)

	for _, Component in pairs (Components) do
		if not Component:IsA("Model") then continue end

		local CFrameGoal = (Component.PrimaryPart.CFrame + Vector3.new(math.random(-20,20),50,math.random(-20,20))) 
			* CFrame.Angles(math.rad(math.random(1,360)), math.rad(math.random(1,360)), math.rad(math.random(1,360)))
	
		local TweenInf = TweenInfo.new(2, Enum.EasingStyle.Linear)
		local Tween = tweenService:Create(Component.PrimaryPart, TweenInf, {CFrame = CFrameGoal})
		Tween:Play()
		local Event = nil
		Event = Tween.Completed:Connect(function()
			Event:Disconnect()
			Component.PrimaryPart.CFrame = Component.PrimaryPart.CFrame - Vector3.new(0, 300, 0)		
		end)
	end

	wait(.5)

	for _, Item in pairs (Effects) do
		if Item:IsA("Beam") or Item:IsA("PointLight") or Item:IsA("ParticleEmitter") then
			Item.Enabled = false
		end
	end

end

function DoorFX.CLOSE(door)
	if not door then return end

	local Components = door:GetChildren()
	for _, Component in pairs (Components) do
		if Component:IsA("Model") then
			Component.PrimaryPart.CFrame = InitialModelCFrames[Component] or Component.PrimaryPart.CFrame 
			--this errors when the module is called for some reason so thats why its like that
		end
	end
end

return DoorFX
