Attempt to get length of a userdata value? | Help is needed!

So, basically I’m practicing my scripting skills and getting this weird error. I’m making a round base hide and seek game.

My whole 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 = 15

while true do
	
	Status.Value = "Waiting for enough players for next round.."
	
	repeat wait(1) until game.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,#player)
			Status.Value = ChosenSeeker.Name.." was choosen as the seeker!"
		end
	end
end

This line is causing the error: local ChosenSeeker = math.random(1,#player)

You have to do #players:GetPlayers() since player is not a table, just an object.

1 Like