Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Keep particles locked on torso after death?

Asked by
MexheCo 46
5 years ago

[USING R6 ANIMATIONS]

I have a button that, when touched by the player, attaches a particle effect to the player's torso.

However, when the player dies/respawns, the particles disappear. Is there any way to keep the particles attached to the player's torso, even after death?

My button script:

local Particles = script.Parent.Parent.ParticlesPart.ParticleEmitter

script.Parent.Touched:connect(function(Part)
local IsPar = Part.Parent.Torso:FindFirstChild("ParticleEmitter")

  if not IsPar then
    local particles = Particles:Clone()
    particles.Parent= Part.Parent.Torso
  else
    Part.Parent.Torso.ParticleEmitter:Destroy()
    local particles = Particles:Clone()
    particles.Parent= Part.Parent.Torso

  end

end)

Thanks in advance, MexheCo

1 answer

Log in to vote
0
Answered by 5 years ago

The problem with your script is that you're wrongly assuming that an object named Torso will be a child of the touching part's parent, when this is not always the case. You must do checks.

local particles = script.Parent.Parent.ParticlesPart.ParticleEmitter

script.Parent.Touched:Connect(function(part)
    -- Switch to :Connect, :connect is deprecated
    local charOrWS = part.Parent

    if charOrWS:FindFirstChild("HumanoidRootPart") then
        if not charOrWS.HumanoidRootPart:FindFirstChild("ParticleEmitter") then
            particles:Clone().Parent = charOrWs.HumanoidRootPart
        else
            print("user already has particles!")
        end
    end
end)

Just for error prevention. I won't be making the script that keeps the particles after death, since you did not attempt it.

0
Understood, I will attempt and re-ask, if that is the correct way to go about things :) Thanks MexheCo 46 — 5y
Ad

Answer this question