Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I detect a players respawn?

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

✓ Accepted answer

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

5 comments

0

Thank you, it works very well. (upvoted :D)

0

-Stamp of goul approval-

0

Your so handsome @CPF2

0

^

0

This was very good

This discussion is preserved as it was. New answers, comments, and votes are closed.