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

How do I get the humanoid for all players in game?

Asked by 9 years ago
1function prepPlayer()
2    local children = game.Players:GetChildren()
3    for i = 1, #children do
4        hum =   children[i].Character:WaitForChild("Humanoid")
5        hum.WalkSpeed = 30
6    end
7end

How do I get the humanoid for all players in game? This is what I have, and I can't figure out what is wrong with the script.

1 answer

Log in to vote
2
Answered by 9 years ago

There doesn't appear to be anything wrong with your code with the exception of a few gotchas and nil checks

1function prepPlayer()
2    local children = game.Players:GetPlayers()
3    for i = 1, #children do
4        local hum =  (children[i].Character or children[i].CharacterAdded:wait()):WaitForChild("Humanoid")
5        hum.WalkSpeed = 30
6    end
7end
Ad

Answer this question