local V={}local y=game:GetService("\084\119\101\101\110\083\101\114\118\105\099\101")local A=TweenInfo.new(1,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut)local j={}function V.OPEN(V)if not V then return end local A=V:WaitForChild("\069\102\102\101\099\116\115")local a=A:GetChildren()for V,y in pairs(a)do if y.Name=="\085\110\108\111\099\107"then y:Play()continue end if y:IsA("\066\101\097\109")or y:IsA("\080\111\105\110\116\076\105\103\104\116")or y:IsA("\080\097\114\116\105\099\108\101\069\109\105\116\116\101\114")then y.Enabled=true end end local E=V:GetChildren()for V,A in pairs(E)do if not A:IsA("\077\111\100\101\108")then continue end local a=A:GetDescendants()for V,y in pairs(a)do if y:IsA("\066\097\115\101\080\097\114\116")and y~=A.PrimaryPart then local V=Instance.new("\087\101\108\100\067\111\110\115\116\114\097\105\110\116")V.Part0=y V.Part1=A.PrimaryPart V.Parent=A.PrimaryPart y.Anchored=false end end j[A]=A.PrimaryPart.CFrame local E=(A.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 K=TweenInfo.new(1,Enum.EasingStyle.Quint,Enum.EasingDirection.In);(y:Create(A.PrimaryPart,K,{CFrame=E})):Play()end wait(1)for V,A in pairs(E)do if not A:IsA("\077\111\100\101\108")then continue end local j=(A.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 a=TweenInfo.new(2,Enum.EasingStyle.Linear)local E=y:Create(A.PrimaryPart,a,{CFrame=j})E:Play()local K=nil K=E.Completed:Connect(function()K:Disconnect()A.PrimaryPart.CFrame=A.PrimaryPart.CFrame-Vector3.new(0,300,0)end)end wait(.5)for V,y in pairs(a)do if y:IsA("\066\101\097\109")or y:IsA("\080\111\105\110\116\076\105\103\104\116")or y:IsA("\080\097\114\116\105\099\108\101\069\109\105\116\116\101\114")then y.Enabled=false end end end function V.CLOSE(V)if not V then return end local y=V:GetChildren()for V,y in pairs(y)do if y:IsA("\077\111\100\101\108")then y.PrimaryPart.CFrame=j[y]or y.PrimaryPart.CFrame end end end return V


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

		local descendants = Component:GetDescendants()
		for _, item in pairs (descendants) do
			if item:IsA("BasePart") and item ~= Component.PrimaryPart then
				local newWeld = Instance.new("WeldConstraint")
				newWeld.Part0 = item
				newWeld.Part1 = Component.PrimaryPart
				newWeld.Parent = Component.PrimaryPart
				item.Anchored = false
			end
		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
