While reading some scripts I came across this code
local function onPlayerAdded(player)
player.CharacterAdded:Connect(onCharacterAdded)
if player.Character then --here it is assumed that there could be a character
onCharacterAdded(player.Character)
end
end
Players.PlayerAdded:Connect(onPlayerAdded)
What makes suppose that the character can be loaded before the PlayerAdded event is fired. Is it possible that this happens?
local function onPlayerAdded(player)
player.CharacterAdded:Connect(onCharacterAdded)
if player.Character then -- This checks if the player's character loaded
onCharacterAdded(player.Character)
end
end
Players.PlayerAdded:Connect(onPlayerAdded) -- this connects the PlayerAdded event to the function