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

Player's character loaded in? [SOLVED]

Asked by 9 years ago

Does anyone know a more efficent find if the player's character is loaded in or not?

This is the way I try it

while wait() do
    if player.Character:FindFirstChild("Humanoid") then
        --code
    end
end

Does anyone know a more better way to find if the player's character is loaded in?

2 answers

Log in to vote
1
Answered by
MrFlimsy 345 Moderation Voter
9 years ago

All events have a wait() method which will wait until the event is triggered. You can use that for the character with the CharacterAdded event.

local player = game.Players.PlayerNameHere
player.CharacterAdded:wait()

Or you could do it like this, although it's less efficient:

local player = game.Players.PlayerNameHere
repeat wait() until player.Character
Ad
Log in to vote
1
Answered by
digpoe 65 Badge of Merit
9 years ago

The average ROBLOX character usually has more than 12 children when it has completely loaded. Twelve children for the minimal 'character', and the extra few hats/shirts/pants etc.

Knowing this, you can do something like this:

game.Players.PlayerAdded:connect(function(Player)
    Player.CharacterAdded:connect(function(Character)
        while #Character:GetChildren() < 12 do
            wait(0.5) -- wait 0.5 seconds every time the number of children in the Character instance is below 12
        end
        print("The base character has completely loaded!")
    end)
end)

Of course, the actual number of instances in a character isn't fixed and could change, so this isn't a perfect answer which will always work.

0
it worked for me, but with 14 instead of 12 Tesouro 407 — 9y

Answer this question