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

How do I detect a players respawn?

Asked by 6 years ago
Edited 5 years ago

I'm trying to run this code every time the player respawns

-- This is what is executed when the player joins the game.

game.Players.PlayerAdded:Connect(function(player)
    local particle1 = game.ReplicatedStorage.ParticleEmitter
    local particle2 = game.ReplicatedStorage.ParticleEmitter2
    local death = game.ReplicatedStorage.death
    local theCharacter = workspace:WaitForChild(player.Name)
    if theCharacter.Humanoid ~= nil then
    particle1:Clone().Parent = theCharacter.Torso
    particle1:Clone().Parent = theCharacter.Head
    particle1:Clone().Parent = theCharacter["Left Arm"]
    particle1:Clone().Parent = theCharacter["Right Arm"]
    particle1:Clone().Parent = theCharacter["Left Leg"]
    particle1:Clone().Parent = theCharacter["Right Leg"]
    particle2:Clone().Parent = theCharacter.Torso
    particle2:Clone().Parent = theCharacter.Head
    particle2:Clone().Parent = theCharacter["Left Arm"]
    particle2:Clone().Parent = theCharacter["Right Arm"]
    particle2:Clone().Parent = theCharacter["Left Leg"]
    particle2:Clone().Parent = theCharacter["Right Leg"]
    death:Clone().Parent = theCharacter
    end
end)

But I need to run this code again on the player that respawns. How would I do that?

1 answer

Log in to vote
2
Answered by
CPF2 406 Moderation Voter
6 years ago

fairly simple, just use the player's CharacterAdded event.

example of what you are trying to do.

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        local particle1 = game.ReplicatedStorage.ParticleEmitter
        local particle2 = game.ReplicatedStorage.ParticleEmitter2
        game.ReplicatedStorage.death:Clone().Parent = character

        for i,v in pairs(character:GetChildren()) do

            if v:IsA("BasePart") and v.Name ~= "HumanoidRootPart" then

                particle1:Clone().Parent = v
                particle2:Clone().Parent = v

            end

        end

    end)
end)

NOTE: I simplified the script a bit, but it still does the same thing

0
Thank you, it works very well. (upvoted :D) LoganboyInCO 150 — 6y
0
-Stamp of goul approval- Goulstem 8144 — 6y
0
Your so handsome @CPF2 DecisiveTech 2 — 6y
0
^ LoganboyInCO 150 — 6y
0
This was very good RavenclawHermitCrab 0 — 3y
Ad

Answer this question