Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Player not in world??

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?

2 comments

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.

0

alpha, i think line 2 does exactly that

2 answers

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.

2 comments

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.

0

This explanation is the correct one, though.

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.

1 comment

0

I already had the variable before the statement, some 60 lines before it

This discussion is preserved as it was. New answers, comments, and votes are closed.