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

Why does this script stop working when I die?

Asked by 9 years ago

This is a serverscript inside Workspace. When I die, the particleemitter leaves, I know why, but I don't know how to fix it.

game.Players.PlayerAdded:connect(function(player)
    repeat wait() until player.Character
local torso = player.Character:WaitForChild("Torso")
local newParticle = game.ServerStorage.ParticleEmitter:Clone()
    newParticle.Parent = torso
local Humanoid = player.Character.Humanoid
Humanoid.HealthChanged:connect(function(NewHealth, player)
     if NewHealth < 25 then --Checks the new health of the humanoid.
        torso.ParticleEmitter.Enabled = true
    else
        torso.ParticleEmitter.Enabled = false
    end
end)
end)

1 answer

Log in to vote
0
Answered by
obcdino 113
9 years ago

Just do a Died event on the character's humanoid. I added a LoadCharacter() to make the character respawn instantly after death.

game.Players.PlayerAdded:connect(function(player)
player.Character.Humanoid.Died:connect(function()
char = player.Character
char:LoadCharacter()
char.Torso.ParticleEmitter.Enabled = true
end)
end)
0
I get this error (I made it a serverscript) 09:00:15.062 - Workspace.Script:2: attempt to index field 'Character' (a nil value) CheekySquid 78 — 9y
0
Your script is correct but you need to wait for the humanoid in the character function. player.Character:WaitForChild("Humanoid").Died:connect(function(char) docrobloxman52 407 — 9y
Ad

Answer this question