CharacterAdded query

Hello,

Sometimes when you have loads of stuff within the PlayerAdded event the CharacterAdded event does not fire on the first character spawn.

In order to solve this, I made use of

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

within the playeradded event and handle the first character spawn there.

Is this the correct way to do this?

Another method I thought of was making use of StarterCharacterScripts.

I don’t see anything wrong with doing that. In fact, I use that a lot in my scripts.

I see, I just wanted to verify whether this was the correct way to do this. Thank you.

I’m concerned by CharacterAdded not firing. I don’t have a ton of experience with it and PlayerAdded, but have you looked for reasons why it might not have fired?

For example, I found this thread: CharacterAdded event not firing

Yes it is indeed related to my issue and the solution does make sense when it says that the character is loaded before the CharacterAdded Event is listening because of the delays within the PlayerAdded Event.

Furthermore, I had already done part of what the solution of that thread says by defining the character within the PlayerAdded event as shown above. However, I will also try loading the character before defining the character to make sure that everything is on time.

Thank you for showing me this post!

1 Like

This indeed works, but you will have an issue with this, because the line of code above, will only be “useful”, for example if it is inside an function,(Fired constantly), because if you put it for example, in the top of the script, your “code” would more likely run ONCE, breaking after the player dies.

This happens due to when an character dies, the Character property from the player, will be nil, and then after loading, it will be the player’s character once again. But as i said, if you put it in an function and that function won’t run once, then the character variable will be updated every time the function is ran.

Sorry if i badly explained this.

I only need it once because then the CharacterAdded will handle the rest of the characterspawns.

I only need this to handle the first character spawn since the event does not listen for the first addition but it definitely does after that.

It will also only run once cause it’s within the PlayerAdded event which only fires once, when the player joins the game.

2 Likes