Whenever I test-play my Hide and Seek game, I always see this error message appear: "invalid argument #2 to 'random' (interval is empty)". How do I solve this issue?
Full Code:
-- Services local replicatedStorage = game:GetService("ReplicatedStorage") local serverStorage = game:GetService("ServerStorage") local status = replicatedStorage:WaitForChild("Values").Status -- Config local playersToStart = 1 -- Functions local function chooseSeeker(availablePlayers) return availablePlayers[math.random(1, #availablePlayers)] end local function teleportPlayers(availablePlayers, spawns) -- availablePlayers: Table / spawns: Table for _, plr in pairs(availablePlayers) do if plr.Character then if plr.Character:FindFirstChild("HumanoidRootPart") then plr.Character.HumanoidRootPart.CFrame = spawns[math.random(1, #spawns)].CFrame + Vector3.new(0,5,6) <-- line with error message end end end end while wait(1) do repeat print("Not enough players in-game!") status.Value = playersToStart.." players or more are needed to start. (/"..playersToStart..")" wait(1) until #game.Players:GetPlayers() >= playersToStart for i = 5,0,-1 do status.Value = "Next round starts in "..i.." seconds." wait(0.1) end local contestants = game.Players:GetPlayers() local seeker = chooseSeeker(contestants) status.Value = "The chosen seeker is... " wait(2) status.Value = seeker.Name.."!" wait(3) local map = workspace.Map teleportPlayers(contestants, map.Spawns:GetChildren()) wait(5) end
According to internet research, you would get an "interval is empty" error if the second argument is less than the first argument. Your spawns table may be empty at times, causing this error; check if this is the case.