--This module is for any client FX related to the Lab's door


local WoodenBarrierFX = {}

local tweenService = game:GetService("TweenService")

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

function WoodenBarrierFX.BREAK(plank)
	if not plank then return end
	
	plank.Transparency = 1
	local plankClone = plank:Clone()
	plankClone.Transparency = 0
	plankClone.CanCollide = false
	plankClone.CanTouch = false
	plankClone.Massless = true
	plankClone.Anchored = true
	
	local smoke = script.Smoke:Clone()
	smoke.Parent = plankClone
	
	plankClone.Parent = workspace.Ignore
	tweenService:Create(plankClone, TweenInfo.new(2, Enum.EasingStyle.Sine, Enum.EasingDirection.In), {Transparency = 1}):Play()
	game.Debris:AddItem(plankClone, 2)
	
	plankClone.CFrame = plank.CFrame

	local velo = plank.CFrame.UpVector * (-25 - math.random() * 10)
	plankClone.Anchored = false
	plankClone.Velocity = velo + Vector3.new(0, 25 + math.random() * 10, 0)
	plankClone.RotVelocity = Vector3.new(math.random() * 20 - 10, math.random() * 20 - 10, math.random() * 20 - 10)
	smoke:Emit(60)
	
end

function WoodenBarrierFX.BUILD(plank)
	if not plank then return end
	
	plank.Transparency = 1
	local plankClone = plank:Clone()
	plankClone.Transparency = 1
	plankClone.CanCollide = false
	plankClone.CanTouch = false
	plankClone.Massless = true
	
	local smoke = script.Smoke:Clone()
	smoke.Parent = plankClone
	local sparks = script.Sparks:Clone()
	sparks.Parent = plankClone
	
	plankClone.Parent = workspace.Ignore
	game.Debris:AddItem(plankClone, 3)
	
	local midCf = plank.CFrame * CFrame.new(0, -5, 0)
	local startCf = midCf - Vector3.new(0, 5, 0)
	local endCf = plank.CFrame
	
	plankClone.CFrame = startCf
	tweenService:Create(plankClone, TweenInfo.new(0.4, Enum.EasingStyle.Back, Enum.EasingDirection.Out), {Position = midCf.Position}):Play()
	tweenService:Create(plankClone, TweenInfo.new(0.2), {Transparency = 0}):Play()
	local originOrientation = plankClone.Orientation
	
	local start = tick()
	while tick() - start <= 0.5 do
		plankClone.Orientation = originOrientation + Vector3.new(math.random() * 6 - 3, math.random() * 6 - 3, math.random() * 6 - 3)
		wait()
	end
	
	tweenService:Create(plankClone, TweenInfo.new(0.1, Enum.EasingStyle.Cubic, Enum.EasingDirection.In), {CFrame = endCf}):Play()
	delay(0.1, function()
		smoke:Emit(60)
		sparks:Emit(30)
	end)
	wait(0.5)
	
	plank.Transparency = 0

end

return WoodenBarrierFX
