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

Why does this script only apply to the first person who gets on?[unanswered]

I have this short part of the script here that I'm using to kill everyone. Unfortunately it seems to only affect the first person. Can someone explain to me what is wrong?

for i,v in pairs(game.Players:GetPlayers()) do
			v.Character.Humanoid.Health = 0

Thanks

4 comments

0

Try connecting to the PlayerAdded event.

0

How would I do that?

0

It's not in a function, and you aren't choosing when to run it. So it just runs at the start of the server. I don't have enough information on why or when you are killing them to help you any further.

0

Have you checked the wiki?

3 answers

This should work, from what you put. Unless you want to loop it. Reply if you wanted something differently.

function onjoin(player)
player:WaitForChild("Character")
player.Character:WaitForChild("Humanoid")
player.Character.Humanoid.Health = 0
end

game.Players.PlayerAdded:connect(onjoin)

Give this answer a like if it helped :)

1 comment

0

Thanks but is there a way to use this without it happening right away. Like after other functions?

You can do this too

game.Workspace.CharacterAdded(function(Character)--if character added to workspace
	character.Humanoid.Health = 0--changes health to 0
end)

there maybe speeling check it once more before executing because i didnt check it

function KillAllPlayersCurrentlyInGame()
	for i,v in pairs(game.Players:GetPlayer()) do
		v.Character:WaitForChild("Humanoid").Health = 0
	end
end

This is a function that kills all players. To make this function run, you have to call it, like this.

KillAllPlayersCurrentlyInGame()

This function will only kill all the players in the game at the time you call it. It will not kill any players that join after you call it.

Please be more specific with your question.

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