Player:WaitForChild("Character") causing infinite wait

game.Players.PlayerAdded:Connect(function(plr)
    local char = plr:WaitForChild("Character")
    repeat wait() until char
  	print("Character loaded.")
end)

So I was making a script and noticed that all functions that are involved with the character were not working. I got suspicious so I made this script and got a warning saying an infinite yield is possible. I checked the player and the character was set. Why is this happening?

3 Likes

Character is a property of the Player, not an Instance. If you want to get or wait for the character you should use
local char = plr.Character or plr.CharacterAdded:Wait()

10 Likes

Player.CharacterAdded:wait() worked, Thanks! :smile::+1:

2 Likes