while wait() do
contestants = {}
for _, player in pairs(game.Players:GetPlayers()) do
if player and player.Character then
local humanoid = player.Character:WaitForChild("Humanoid")
if humanoid and humanoid.Health > 0 then
table.insert(contestants, player)
end
end
end
if #contestants >= 2 then
break
else
statustag.Value = "Waiting for enough players"
timertag.Value = -1
end
end
for _, player in pairs(contestants) do
local duelplayers = {}
local randomplayers = contestants[math.random(2, #contestants)]
table.insert(duelplayers, randomplayers)
statustag.Value = duelplayers[1].Name .. " vs. " .. duelplayers[2].Name -- ERROR HERE (163)
Instance.new("StringValue", script.Dueling).Name = duelplayers[1].Name
Instance.new("StringValue", script.Dueling).Name = duelplayers[2].Name
duelplayers[1]:MoveTo(arena:WaitForChild("Spawn1").Position)
duelplayers[2]:MoveTo(arena:WaitForChild("Spawn2").Position)
end
20:42:38.388 - ServerScriptService.MainScript:163: attempt to index field '?' (a nil value)
I'm trying to get 2 random players out of the 'contestants' table and then I want to create a new Instance with the Name of the 'StringValue' to the name of the first player and then another of the second player, then teleport the player to spawn1 and spawn2. I don't know what the error is, but I think it has something to do with how I am making setting the tables out. Thanks.

5 comments
"Be sure to accept it"
It works, but theres an error saying MoveTo is not part of player
MoveTo is a property of the player's character, so just .Character after duelplayers[1] and duelplayers[2] on lines 29 and 30. I've also fixed this myself.
I have discovered a bug. It creates 4 string values inside Duel, 2 for one player and the other 2 for the other. Why is it creating 4, when it should only create 2?
Get rid of the for loop on line 19, it's not needed. I'll also edit my answer.