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

Player's character loaded in? [SOLVED]

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

✓ Accepted answer

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

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.

1 comment

0

it worked for me, but with 14 instead of 12

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