for _, player in pairs(game.Players:GetPlayers()) do
if player then
player:LoadCharacter() -- ERRORS HERE!!
end
end
You haven’t checked for the character, just the player.
LoadCharacter doesn’t require the character to be loaded in tho
that’s a very good point
I can’t see any reason why this code would be erroring. Either way you need to wrap this in a pcall for when players leave part way through the loop running.
All I can imagine this meaning is that the player has to be a descendant of the DataModel, though I don’t know why you would receive the player before that condition is true. Either way, try printing the parent of the player object right before calling LoadCharacter.
If that isn’t the issue, then I’d personally say the error description offers no information which would help any developer fix the bug.
LoadCharacter
yields, so it’s possible that players leave while e.g. the 1st player’s character is being loaded.
You can check if player.Parent then .... end
to check if the player is still in the game. (player
on its own won’t ever be nil as GetPlayers
returns an array of players that are in the game at the time you call that function.)
Alternatively, load all characters in parallel (avoid spawn
here, it waits with resume-ing the spawned thread one tick, so the player could have left in that case…):
for _, player in pairs(game.Players:GetPlayers()) do
coroutine.wrap(function()
player:LoadCharacter()
end)()
end
Put it in a pcall() , spawn() , and while loop check