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

How to make a script that kills the player on join?

Asked by 6 years ago
Edited 6 years ago

I tried to make a script that kills the player when he joined (because there's a spawn bug) but I don't know how. Can you please help me?

0
Hey you. Yes you. The title of this website is "Scripting Helpers". Actually TRY before asking for help. And we'll correct you. Don't expect us to always just make you a script. DaWarTekWizard 169 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

First your going to want to use a PlayerAdded event

game.Players.PlayerAdded:connect(function(player)
--Code Goes here
end)

Then your going to want to kill the player, the way you can do this is by waiting for the characater then getting the humanoid and setting the health to zero and removing the forcefield.

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)

That should work

0
That'll keep firing whenever a player respawns; in short, it'll loopkill. Use `player.CharacterAdded:Wait()` instead. :P TheeDeathCaster 2368 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

I suggest this being a Server Script:

game:GetService("Players").PlayerAdded:Connect(function(plr)
    local character = plr.CharacterAdded:Wait()
    character:WaitForChild("ForceField"):Destroy()
    character:WaitForChild("Humanoid").Health = 0
end)

Hope this works!

Answer this question