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
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].