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

6 comments
I'm not sure but I don't THINK # can be used in Lua coding
can be used in Lua.
Oh i didn't know that thanks
Quick Question what line does it say it has the error on the output on.
The line it says it has the error on the output on is Line 20.
Can't test right now so I don't know if this helps or not, you may already know this but pretty sure that the game is detecting that you have no spawn locations. Maybe test with printing spawns to see what it says.