--//both of you, dance like you want to win!


local SSS = game:GetService("ServerScriptService")
local TS = game:GetService("TweenService")
local Global = require(SSS.Server.Scripts.Server.CoreSystems.Modules.Global)

local Deb = false
local Status = false

local function Toggle()
	if not Deb then
		if not Status then --open
			Deb = true
			script.Parent.Sound.vaultdooropen:Play()
			if script.Parent.Vault.Door.VaultHandle:FindFirstChild("Motor") then
				TS:Create(script.Parent.Vault.Door.VaultHandle.Motor.HingeConstraint, TweenInfo.new(2), {AngularVelocity = -30}):Play()
			end
			wait(1.8)
			if script.Parent.Vault.Door.VaultHandle:FindFirstChild("Motor") then
				TS:Create(script.Parent.Vault.Door.VaultHandle.Motor.HingeConstraint, TweenInfo.new(4), {AngularVelocity = 0}):Play()
			end
			for i = 7,11 do
				Global.TweenModelBounceOut(script.Parent["Bar"..i].Bar, script.Parent["Bar"..i].ToGo.CFrame, true, .15)
			end
			
			wait(.9)
			for i = 1,3 do
				Global.TweenModelBounceOut(script.Parent["Bar"..i].Bar, script.Parent["Bar"..i].ToGo.CFrame, true, .375)
			end
			
			wait(1)
			for i = 4,6 do
				Global.TweenModelBounceOut(script.Parent["Bar"..i].Bar, script.Parent["Bar"..i].ToGo.CFrame, true, .375)
			end
			
			wait(.7)
			script.Parent.Vault.Door.VaultHandle.Motor.Anchored = true
			Global.TweenModel(script.Parent.Vault.Door, script.Parent.Vault.ToGo.CFrame, true, 6.5)
			
			wait(7)
			Status = true
			Deb = false
		else
			Deb = true
			script.Parent.Sound.vaultdoorclose:Play()
			Global.TweenModel(script.Parent.Vault.Door, script.Parent.Vault.Org.CFrame, true, 6.5)
			script.Parent.Vault.Door.VaultHandle.Motor.Anchored = false
			
			wait(1.3)
			if script.Parent.Vault.Door.VaultHandle:FindFirstChild("Motor") then
				TS:Create(script.Parent.Vault.Door.VaultHandle.Motor.HingeConstraint, TweenInfo.new(2), {AngularVelocity = 30}):Play()
			end
			wait(1.8)
			if script.Parent.Vault.Door.VaultHandle:FindFirstChild("Motor") then
				TS:Create(script.Parent.Vault.Door.VaultHandle.Motor.HingeConstraint, TweenInfo.new(4), {AngularVelocity = 0}):Play()
			end
			for i = 7,11 do
				Global.TweenModelBounceOut(script.Parent["Bar"..i].Bar, script.Parent["Bar"..i].Org.CFrame, true, .15)
			end
			
			wait(1.2)
			for i = 1,3 do
				Global.TweenModelBounceOut(script.Parent["Bar"..i].Bar, script.Parent["Bar"..i].Org.CFrame, true, .375)
			end
			
			wait(.75)
			for i = 4,6 do
				Global.TweenModelBounceOut(script.Parent["Bar"..i].Bar, script.Parent["Bar"..i].Org.CFrame, true, .375)
			end
			
			wait(3.5)
			Status = false
			Deb = false
		end
	end
end

script.Parent.ClickDetector.MouseClick:Connect(Toggle)
