You can do things when the character spawns by using the CharacterAppearanceLoaded
event, which is just like CharacterAdded, but it waits for the assets to load.
01 | game.Players.PlayerAdded:connect( function (player) |
02 | player.CharacterAppearanceLoaded:connect( function (character) |
03 | for _,v in pairs (character:GetChildren()) do |
04 | if v:IsA( "CharacterAppearance" ) then |
07 | game.ServerStorage.HeadMesh:clone().Parent = character.Head |
An even better way to not have to deal with character assets is to set Player.CanLoadCharacterAppearance
to false when they join.
edit:
Player.CharacterAdded
is an event of the Player class. It is fired when a player respawns or when Player:LoadCharacter()
is called, and it provides the new character as an argument.
1 | game.Players.PlayerAdded:connect( function (player) |
2 | player.CharacterAdded:connect(functon(char) |
3 | print (char.Name.. "'s character spawned" ) |
Player.CharacterAppearanceLoaded
does the same thing, but it doesn't fire immediately when the character spawns. Instead, it waits for the hats, packages, etc. to load into the character object. If you were to try to access (or remove) these objects before they loaded, they would not be there yet.