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

How do you kill a player when they join?

Asked by 4 years ago

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
Quick tip, changing Humanoid HP directly (like when you did Health=0) goes through ForceFields, as they can only block TakeDamage() and explosions. hoyhyo 2 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

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)
0
HumanoidRootPart or Head would be a better thing to remove as it's intertwinable between r6, r15, rthro and future types. Gojinhan 353 — 4y
Ad

Answer this question