How do i detect when a player character has been loaded client sided?, in a local script.
Player.CharacterAppearanceLoaded
https://developer.roblox.com/en-us/api-reference/event/Player/CharacterAppearanceLoaded
Works in server scripts also.
There are many ways to achieve this. One technique I always use is portrayed by the following code.
--Inside of a LocalScript
local player = game.Players.LocalPlayer
repeat task.wait() until player.Character --Repeats the wait function until player.Character exists
local character = player.Character --Stores character as a variable
local humanoid = character:WaitForChild("Humanoid") --Still need to use :WaitForChild to access any children of character since those have not necessarily loaded in yet
--etc...
Essentially, I use a repeat statement to repeat nothing until player.Character exists. Once it does exist, I store it in a variable.
Keep in mind that just because the character exists at a specific point in time of its loading doesn’t mean its children do. It is safe practice to use :WaitForChild to get any children of the character while the character is loading in.
Hope this helps.
Hi, you can do this using the CharacterAdded
event.
Ex:
game.Players.LocalPlayer.CharacterAdded:Connect(function()
-- rest here
end)
If you want to take this approach, you can simplify things by writing
--Inside of a LocalScript
local player = game.Players.LocalPlayer
local character = player.CharacterAdded:wait()
--etc...