So I’m adding a sword fighting arena to my game, and the teleportation door is in the lobby. When a player touches it, if they have enough wins earned (10) then it teleports them into the arena and sets their AFK to true so if they are in the arena they don’t get teleported into the match. For a little while players with 10+ wins get teleported and it works just fine, but after a certain amount of time I start getting this error (and players can no longer teleport)
It says the math.random interval is empty (arg 2), but it isn’t empty. Any help would be greatly appreciated.The teleportation script that’s getting the error after a while, but works fine for a little bit at the beginning of the server
local db = false;
local swordSpawns = game.Workspace:WaitForChild("SwordArenaSpawns"):GetChildren()
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if not db then
db = true
for _, player in pairs(game.Players:GetPlayers()) do
if player then
if player.Name == hit.Parent.Name then
if game:GetService("ServerStorage"):WaitForChild("Players")[player.Name].Wins.Value >= 10 then
local playerRoot = hit.Parent:WaitForChild("HumanoidRootPart")
local allSwordSpawns = math.random(1, #swordSpawns) -- This is where the error appears
local randomSpawn = swordSpawns[allSwordSpawns]
if randomSpawn and playerRoot then
table.remove(swordSpawns, allSwordSpawns)
playerRoot.CFrame = CFrame.new(randomSpawn.Position + Vector3.new(0, 1, 0))
wait()
game:GetService("ServerStorage"):WaitForChild("Players")[player.Name].isAFK.Value = true
wait()
game:GetService("ServerScriptService").Remotes.AFKTag:Clone().Parent = playerRoot
game.ReplicatedStorage:WaitForChild("ServerClientAFK"):FireClient(player, "toSword")
game.ReplicatedStorage:WaitForChild("AFKRound"):FireClient(player, "InRound")
end
end
end
end
end
wait(2)
db = false
end
end
end)
Thanks! Just let me know if you need more information!