Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

interval is empty? sorry for the multiple ?'s

Asked by 8 years ago

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
Please code block the code-segment. DigitalVeer 1473 — 8y
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). TheeDeathCaster 2368 — 8y

1 answer

Log in to vote
-2
Answered by
Validark 1580 Snack Break Moderation Voter
8 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your 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)
Ad

Answer this question