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

function prepPlayer() local children = game.Players:GetChildren() for i = 1, #children do hum = children[i].Character:WaitForChild("Humanoid") hum.WalkSpeed = 30 end end

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

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

Answer this question