How to detect that Character is fully loaded in Local script?

Hello
I want to execute action in local script when player’s character is fully loaded.
CharacterAdded and CharacterAppearanceLoaded does not seem to fire at all in the Local script?
Should I place a script inside StarterCharacterScripts and hope that it will be executed only after the Character is fully loaded on the client?

Thanks

3 Likes

CharacterAppearanceLoaded should run on the client?

local player = game.Players.LocalPlayer
player.CharacterAppearanceLoaded:Wait()
print("Appearance loaded")
1 Like

It does not work for me
I have several scripts in StarterPlayerScripts and Roblox puts several more system scripts there.
May be the event fires while one of the other scripts is executing and before my script has a chance to wait or to subscribe to the event…

1 Like

Hello Tati,
the answer you are looking for is the following.

local player_Local = game.Players.LocalPlayer

repeat task.wait() until player_Local.Character

local player_Local_character = player_Local.Character

This method uses the in built task library Roblox provides & will (yield) retry until a Character is loaded in fully.

It will work in any valid local script container (:

2 Likes

Roblox already has a built-in feature that allows you to wait for the character without a repeat.

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
2 Likes

Polling like this is bad; that code is going to run every heartbeat when it shouldn’t.


There are two ways on doing this, but I recommend the second and I’ll explain why.

Ternary Operators

local Character = Player.Character or Player.CharacterAdded:Wait()

Seperate Logic in Functions

local Player = game:GetService("Players").LocalPlayer

local function OnCharacterAdded(Character)
	
end

local function OnCharacterRemoving(Character)
	
end

if Player.Character then OnCharacterAdded(Player.Character) end

Player.CharacterAdded:Connect(OnCharacterAdded)
Player.CharacterRemoving:Connect(OnCharacterRemoving)

They reason I’d recommend the second is because it will gaurentee all your logic is going to be ran everytime the character spawns/despawns without having to reclone the script (You don’t need to put your LocalScript in a container that resets on Player death).

2 Likes

This CharacterAdded:Wait() feature does not work 100% of the time. It is simply prone to error with a nil value.

Magma, there are many ways to go at it. The method I recommended runs around 6 times (heartbeats) the last time I checked. Ensuring values are not nil should be a bigger priority, thus the script I recommended will retry until it retrieves something of value. If you are concerned about the amount of times it runs, you could always configure the wait time or a max amount of retries.

Contextual to his use case, however I believe he only wanted to know how you detect a fully loaded in Character.

Hello!!! idk if you found your solution but you should use ContentProvider like

local ContentProvider = game:GetService("ContentProvider")
ContentProvider:PreloadAsync({plr.Character})

ContentProvider | Documentation - Roblox Creator Hub for more info

Sorry if this seems a bit rude, but… have you checked the doc of ContentProvider? It doesn’t preload models, it preloads assets like decals or sounds. About the main topic, why don’t you wait until something inside the Character loads, like:

local LocalPlayer = game.Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")

Maybe waiting for important character components? Because if it doesn’t work because you have a bunch of Local scripts maybe you should start optimizing it

1 Like