Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

LoadCharacter is giving me errors about how the player is not in the world?

Asked by 5 years ago
Edited 5 years ago

So I am trying to respawn all the players with LoadCharacter on the server but I am getting the error "LoadCharacter can only be called when Player is in the world."

My script:

function SpawnPlayers()
    print("Spawining Players")
    for i, player in ipairs(players) do
        player:LoadCharacter()
    end
end
0
It means the player has not join the game yet MrGaming4me 28 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

You are probaly using the "players" in line 3 as a varible that says "game.Players:GetPlayers()" or "game.Players:GetChildern()" but when you do that, it does not do the players in a table again. So it tries to put all the players in a table when you assing the table. But then the players are not in the game yet. So you should instead use

    function SpawnPlayers()
        print("Spawining Players")
        for i, player in in pairs(game.Players:GetPlayers()) do
            player:LoadCharacter()
        end
    end

so it will go through all the players that are currently in the game and not only the players when you assinged the table. I hope this helps

Ad

Answer this question