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

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

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?

1 comment

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.

2 answers

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

1 comment

0

That'll keep firing whenever a player respawns; in short, it'll loopkill. Use player.CharacterAdded:Wait() instead. :P

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!

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