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

ServerScriptService.Script:29: attempt to get length of global 'Players' (a nil value) ?


local mode = true



game.Players.PlayerAdded:connect(function(plr)
	if mode == true then
		plr.TeamColor = game.Teams["Humans"].TeamColor
	else
		plr.TeamColor = game.Teams["Creepers"].TeamColor
	end
end)


while true do
	wait(1)
	if game.Players.NumPlayers > 1 then
		print "Starting game"
		
		for i = 5, 1, -1 do
			print(i .. " seconds until night")
			wait(1)
		end
		print "Night Begins"
				

local Plrs = game.Players:GetPlayers() 

local creeper = Plrs[math.random(1,#Players)]


print('Selected player was: ' ..creeper.Name)

else
	print "There needs to be 2 players to start"

end
end


script breaking at chosing random players?

2 comments

1

"#Players". Players isn't defined anywhere. Try replacing that with #Plrs.

0

oh thx

1 answer

✓ Accepted answer

You never stated what Players was.

Line 28. You need a table containing a list of players.

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