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?
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