Will this line of code return player's character after it got added?

Hello guys, I have just 1 small question:
Will this line of code wait until player’s character added and then write it into variable?
local CurrentCharacter = Player.Character or Player.CharacterAdded:Wait()

1 Like

Long answer: If the character does not exist when the variable is first defined then it would write it. However, the next time it is called the character is guaranteed to exist and it will return player.Character since it has already waited for the character to be added

Short answer: Yes

You can learn more about the or operator here

1 Like

So, if I call this Once and character don’t exist at that point, what it will do? just wait or return character? or both?

It will won’t return the character when it is first defined if it had to wait for the character. However, it will wait only if the character is not loaded.

Here’s an example:

print(player.Character or player.CharacterAdded:Wait())
--if the above line had to wait because the character is not loaded, it will not return
local character = player.Character or player.Character:Wait()
print(character)
--This will always return the character
1 Like