Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

interval is empty? sorry for the multiple ?'s

Im having trouble with the script again! sorry D:

local allPlayers = {}
for a,v in pairs(game.Players:GetChildren(2)) do 
		table.insert(allPlayers,v)
end
local plrAmount = game.Players.NumPlayers
local val1 = math.random(plrAmount)
local val2 
repeat
	val2 = val2 - math.random(plrAmount)
	wait(2)
until val2 ~=val1
allPlayers[val1].Character.Torso.CFrame = CFrame.new(0,0,0)
allplayers[val2].Character.Torso.CFrame = CFrame.new(665.995,7.1,-115.005)
math.randomseed(os.time())

it says (in output) Workspace.Script:6: bad argument #1 to 'random' (interval is empty) pls help

2 comments

2

Please code block the code-segment.

0

Your problem is because, at the time of Execution of the Chunk, there may be no Players in the game, thus the Table has nothing in it, and so, it is returning an Error saying that the Table is Empty (Math.Random, because your not giving a Valid Argument).

1 answer

✓ Accepted answer

I switched our GetChildren() with GetPlayers(). Also moved math.randomseed to be before math.random, so the sequence generated is different each time.

local allPlayers = {}
for a,v in pairs(game.Players:GetPlayers()) do 
        table.insert(allPlayers,v)
end
local plrAmount = game.Players.NumPlayers
math.randomseed(tick())
local val1 = math.random(plrAmount)
local val2 
repeat wait()
    val2 = math.random(plrAmount)
until val2 ~=val1

allPlayers[val1].Character.Torso.CFrame = CFrame.new(0,0,0)
allplayers[val2].Character.Torso.CFrame = CFrame.new(665.995,7.1,-115.005)

This discussion is preserved as it was. New answers, comments, and votes are closed.