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

How do you kill a player when they join?

I want to kill a player once as soon as they join. Here is my code:

game.Players.PlayerAdded:connect(function(player)
	game.Players.PlayerAdded:connect(function(player) --Waits for player
    player.CharacterAdded:connect(function(char) --Waits for character
        wait() --Waits so they can kill
        char:WaitForChild("ForceField"):Destroy() --Destroys ForceField
        char:WaitForChild("Humanoid").Health=0 --Sets Health to zero
    end)
end)
end)

I do not understand why this is working. Can someone help?

1 comment

1

Quick tip, changing Humanoid HP directly (like when you did Health=0) goes through ForceFields, as they can only block TakeDamage() and explosions.

1 answer

You checked for the player being added twice. I changed this so you don't have to use character added, if you used CharacterAdded, then it would kill the player every time you spawned. WaitForChild will wait until the player is loaded into the game. Destroying the Torso will not make you have to remove the ForceField.

game.Players.PlayerAdded:connect(function(player)
	local char = workspace:WaitForChild(player.Name)
	char:WaitForChild("Torso"):Destroy()
end)

1 comment

0

HumanoidRootPart or Head would be a better thing to remove as it's intertwinable between r6, r15, rthro and future types.

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