Does CharacterAdded:Wait() stop yielding if the player leaves/isn't in game?

Sorry if this is a silly question! I just couldn’t find a clear answer and was curious about it. The reason I’m asking is I’ve noticed sometimes my game will stop during the character loading phase but it won’t error. This is what I use to grab their character, and the player is an argument sent into the function.

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

The player.CharacterAdded:Wait() will stop yielding once the character is added. Also what do you mean by the game softlock-ing?

Short answer; no.
Long answer; no because if a player leaves the server while its looking for their character, then it will be looking for a character that will never be added, therefore yielding forever. Same reason that a script will never stop yielding with Tween.Completed:Wait() or Sound.Ended:Wait() if neither ever finish.

I tested this pretty easily just by booting up a local server in studio and leaving before it checked for the character.

local PlayerService = game:GetService("Players")

PlayerService.PlayerAdded:Connect(function (Player)
	task.wait(5)
	local Character = Player.Character or Player.CharacterAdded:Wait()
	print("Pass")
end)

Although i’m gonna be honest, this shouldn’t be an issue at all unless you are waiting for something else before you check the character for some reason.
I guess to circumvent this you could do something like:

local Player = blah blah blah
local Character = workspace:WaitForChild(Player.Name, 5)

But that feels really silly and unnecessary. You should be fine.

2 Likes

Thank you! This is exactly what I was curious about.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.