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

Player not in world??

Asked by 8 years ago

Hey guys, I got this error message:

22:12:22.155 - LoadCharacter can only be called when Player is in the world 22:12:22.168 - Script 'ServerScriptService.Script', Line 96 - global Classic 22:12:22.175 - Script 'ServerScriptService.Script', Line 189 - global ChooseRound 22:12:22.178 - Script 'ServerScriptService.Script', Line 202 22:12:22.180 - Stack End

Here is where I think the problem lies:

for i = 1,#players do
        if players[i] then
        players[i].TeamColor = game.Teams['Not Playing'].TeamColor
        players[i]:LoadCharacter()end --This is line 96
    end

Why am I getting this error message even though I have put in a check to see if the player ~= nil?

0
I am not sure due to never recieving this error, but make sure that the player being loaded exists in the server. That it's not a name of a player whom is not playing. alphawolvess 1784 — 8y
0
alpha, i think line 2 does exactly that fahmisack123 385 — 8y

2 answers

Log in to vote
3
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
8 years ago

if players[i] then will always be true. A player is not nil if it is not in players; it still is a player. Instead, write if players[i].Parent then to make sure that they are still there. LoadCharacter cannot be called otherwise.

0
Thank you for your answer, I appreciate it. However, there are some other users that have given me different solutions that have more preferable explanations. fahmisack123 385 — 8y
0
This explanation is the correct one, though. 1waffle1 2908 — 8y
Ad
Log in to vote
-1
Answered by 8 years ago
local players = Game.Players:GetPlayers()

for i = 1, #players do
    players[i].TeamColor = game.Teams['Not Playing'].TeamColor
    players[i]:LoadCharacter()
end

This should work fine? My guess is that your table "players" has something wrong with it.

0
I already had the variable before the statement, some 60 lines before it fahmisack123 385 — 8y

Answer this question