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

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

Asked by
wjs3456 90
9 years ago

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

0
Try connecting to the PlayerAdded event. GoldenPhysics 474 — 9y
0
How would I do that? wjs3456 90 — 9y
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. Aethex 256 — 9y
0
Have you checked the wiki? GoldenPhysics 474 — 9y

Closed as Too Broad by Aethex, Perci1, and BlueTaslem

This question has been closed because it is too broad and is generally unanswerable. Please ask a more specific question.

Why was this question closed?

3 answers

Log in to vote
0
Answered by 9 years ago

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 :)

0
Thanks but is there a way to use this without it happening right away. Like after other functions? wjs3456 90 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

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

Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago
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.