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?
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…
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).
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.
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