local v=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local E=game:GetService("\068\101\098\114\105\115")local F={}F.__index=F F.ClassName="\080\097\114\116\105\099\108\101\080\108\097\121\101\114"function F.new()local v=setmetatable({},F)return v end function F.PlayLevelUpEffect(F,E)if not E then warn("\091\080\097\114\116\105\099\108\101\080\108\097\121\101\114\093 - \078\111 \104\117\109\097\110\111\105\100")return false end local N=Instance.new("\065\110\105\109\097\116\105\111\110")N.AnimationId="\114\098\120\097\115\115\101\116\105\100\058\047\047\049\048\057\055\054\053\048\049\055\049"local Q=E:LoadAnimation(N)Q:Play()return F:_playHumanoidEffect(E,v.Particles.LevelUpEffect)end function F._playDescendantsOnce(E,v)local F=0 for v,E in pairs(v:GetDescendants())do if E:IsA("\080\097\114\116\105\099\108\101\069\109\105\116\116\101\114")then E:Emit(E.Rate)F=math.max(F,E.Lifetime.Max)end end return F end function F._playHumanoidEffect(N,v,F)local Q=v.RootPart if not Q then warn("\091\080\097\114\116\105\099\108\101\080\108\097\121\101\114\093 - \078\111 \114\111\111\116 \112\097\114\116")return false end local c=F:Clone()local l=c:FindFirstChild("\067\111\114\101")if not l then warn("\091\080\097\114\116\105\099\108\101\080\108\097\121\101\114\093 - \078\111 \099\111\114\101")return false end for v,F in pairs(l:GetChildren())do if F:IsA("\065\116\116\097\099\104\109\101\110\116")then F.Parent=Q local v=N:_playDescendantsOnce(F)E:AddItem(F,v)end end for F,c in pairs(c:GetChildren())do if c~=l then local F=l.CFrame:toObjectSpace(c.CFrame)c.CFrame=Q.CFrame:toWorldSpace(F)c.CanCollide=false c.Anchored=false local V=Instance.new("\087\101\108\100")V.Parent=c V.Part0=c V.Part1=Q V.C1=F V.Name="\080\097\114\116\105\099\108\101\069\109\105\116\116\101\114\087\101\108\100"c.Parent=v.Parent local m=N:_playDescendantsOnce(c)E:AddItem(c,m)end end return true end return F
--- Plays particle effects for players
-- @classmod ParticlePlayer

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Debris = game:GetService("Debris")

local ParticlePlayer = {}
ParticlePlayer.__index = ParticlePlayer
ParticlePlayer.ClassName = "ParticlePlayer"

function ParticlePlayer.new()
	local self = setmetatable({}, ParticlePlayer)

	return self
end

function ParticlePlayer:PlayLevelUpEffect(humanoid)
	if not humanoid then
		warn("[ParticlePlayer] - No humanoid")
		return false
	end

	-- Load animation
	local animation = Instance.new("Animation")
	animation.AnimationId = "rbxassetid://1097650171"

	local track = humanoid:LoadAnimation(animation)
	track:Play()

	return self:_playHumanoidEffect(humanoid, ReplicatedStorage.Particles.LevelUpEffect)
end

function ParticlePlayer:_playDescendantsOnce(parent)
	local longestLife = 0

	for _, item in pairs(parent:GetDescendants()) do
		if item:IsA("ParticleEmitter") then
			item:Emit(item.Rate)
			longestLife = math.max(longestLife, item.Lifetime.Max)
		end
	end

	return longestLife
end

function ParticlePlayer:_playHumanoidEffect(humanoid, effectTemplate)
	local rootPart = humanoid.RootPart
	if not rootPart then
		warn("[ParticlePlayer] - No root part")
		return false
	end

	local effect = effectTemplate:Clone()
	local core = effect:FindFirstChild("Core")
	if not core then
		warn("[ParticlePlayer] - No core")
		return false
	end

	for _, child in pairs(core:GetChildren()) do
		if child:IsA("Attachment") then
			child.Parent = rootPart

			local longestTime = self:_playDescendantsOnce(child)
			Debris:AddItem(child, longestTime)
		end
	end

	-- Add non-core items to
	for _, part in pairs(effect:GetChildren()) do
		if part ~= core then
			local relative = core.CFrame:toObjectSpace(part.CFrame)
			part.CFrame = rootPart.CFrame:toWorldSpace(relative)

			part.CanCollide = false
			part.Anchored = false
			--part.Transparency = 1

			local weld = Instance.new("Weld")
			weld.Parent = part
			weld.Part0 = part
			weld.Part1 = rootPart
			weld.C1 = relative
			weld.Name = "ParticleEmitterWeld"

			part.Parent = humanoid.Parent
			local longestTime = self:_playDescendantsOnce(part)

			Debris:AddItem(part, longestTime)
		end
	end

	return true
end

return ParticlePlayer