Error: bad argument #2 to 'random' (interval is empty)
I am trying to make a 1v1 game and choosing 2 opponents and making sure they are both not the same person, can someone help?
Code:
wait(1)
local players = game.Players:GetPlayers()
local maps = game:GetService("ServerStorage").Maps:GetChildren()
local runningmaps = workspace:WaitForChild("RunningMaps")
function hint(text)
for i, player in pairs(players) do
player:WaitForChild("PlayerGui").MainGui.hint.Text = tostring(text)
end
end
function shout(text)
for i, player in pairs(players) do
player:WaitForChild("PlayerGui").MainGui.shout.Text = tostring(text)
end
end
while true do
hint("Welcome to Sword Fighting Practice!")
wait(3)
hint("Intermission: 15 seconds")
for i=15,1,-1 do
hint("Intermission: " ..i.. " seconds")
if i < 2 then
hint("Intermission: " ..i.. " second")
end
wait(1)
end
hint("")
shout("Choosing a random map...")
randommap = math.random(1,#maps)
mapchosen = maps[randommap]
wait(3)
shout("Map Chosen: " ..mapchosen.Name)
wait(3)
local mapClone = mapchosen:Clone()
mapClone.Parent = runningmaps
local opponent1 = players[math.random(1,#players)] -- Error starts here
local opponent2 = players[math.random(1,#players)]
local spawns = mapClone:WaitForChild("Spawns")
if opponent1.Character.Name ~= opponent2.Character.Name and opponent2.Character.Name ~= opponent1.Character.Name then
print("True")
for i,v in pairs(opponent1, opponent2) do
if spawns then
opponent1.Character:WaitForChild("Torso"):MoveTo(spawns.Position)
end
end
else
repeat local opponent1 = players[math.random(1,#players)] local opponent2 = players[math.random(1,#players)] wait() until opponent1.Name ~= opponent2.Name and opponent2.Name ~= opponent1.Name
end
--for i,v in pairs()
wait()
end

6 comments
What line is the error on?
41
That is weird, it should work.
Yeah.
opponent1.Name ~= opponent2.Name and opponent2.Name ~= opponent1.Name is redundant. Put print(#players) before line 41. It should say 0 when it errors. Are you removing players from the players table?
I put it and it says 0 when it errors, and I am trying to choose two opponents and making sure they're both not the same person.