1 is not a valid member of players

I’m getting the error: 1 is not a valid member of players and I don’t understand. I’m using a table, not an object but still.

My script:

		--// Variables
	
local ReplicatedStorage = game:GetService("ReplicatedStorage")
	
local ServerStorage = game:GetService("ServerStorage")
	
local Status = ReplicatedStorage:WaitForChild("GameRounds").Status

local Players = game:GetService("Players")
	
local intermissionDelay = 1
	
while true do
		
	Status.Value = "Waiting for enough players for next round.."
		
	repeat wait(1) until Players.NumPlayers >= 1
		
	Status.Value = "Intermission:"..intermissionDelay
		
	intermissionDelay = intermissionDelay - 1
		
	if intermissionDelay == 0 then
			
		for _, player in pairs(Players:GetPlayers()) do
				Status.Value = "Choosing seeker.."
				     wait(1)
				     local ChosenSeeker = math.random(1,#Players:GetPlayers())
				     Status.Value = ChosenSeeker.Name.." was choosen as the seeker!"
				     local Character = player.Character
				     Character:FindFirstChild("HumanoidRootPart").CFrame = CFrame.new(326.64, 9.935, 109.97) + Vector3.new(0,5,0)
				     ChosenSeeker.Character:FindFirstChild("HumanoidRootPart").CFrame =  CFrame.new(335, 12.913, 181) + Vector3.new(0,2,0)
				     for i = 60,1,-1 do
					 Status.Value = "The round will end in "..i.." seconds"
					 
			end
		end
	end
end

You need to do game.Players:GetPlayers()[math.random(1, #players:GetPlayers())]. Right now, the chosen one is only a number not an object.

So, you’re doing 1.Name basically.

Edit: I changed the code a little form @Mixu_78’s correction. Thanks!

2 Likes

by the way, math.random() returns an integer, you’re trying to do Number.Name basically.

Try getting the ChosenSeeker like this

Players[math.random(1,#Players:GetPlayers())]

Edit: Players here is an array of all Players

1 Like

Literally the same error. :frowning: (30 chars)

by Players I meant an array of Players, like

Players = game:GetService("Players"):GetPlayers()
1 Like

I’m, it’s still the same error…

no, I meant when you select a random player

 local ChosenSeeker = Players:GetPlayers()[math.random(#Players:GetPlayers())]
1 Like

Alright works but why do we need to use:GetPlayers() though?

Players:GetPlayers() returns an array of all player objects under game.Players, game.Players itself is a service.

You can’t get the length of Players (userdata), so #Players would error, and

Players[math.random()]

would index a number under Players, which would not make sense;

Players:GetPlayers()

returns an array (numerically indexed table basically) so you can do Players:GetPlayers()[1], Players:GetPlayers()[2] but not Players[1] or Players[2].

2 Likes