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

14: bad argument #2 to 'random' (interval is empty)?

Asked by
KAAK82 16
10 years ago
local Players = game.Players:GetPlayers()
local TopHat = { }
fBeastSpawn = game.Workspace.Map1.MapData.BeastSpawns.fBeastSpawn
sBeastSpawn = game.Workspace.Map1.MapData.BeastSpawns.sBeastSpawn
BeastSpawns = {fBeastSpawn, sBeastSpawn}

table.insert(TopHat, Player)
for _, Player in pairs(Players) do
for i = 1, Player.chancestats.RW.Value do 
TopHat[#TopHat + 1] = Player 
end
end

local Beast = TopHat[math.random(1, #TopHat)]

1 answer

Log in to vote
0
Answered by
MrFlimsy 345 Moderation Voter
10 years ago

That error means the math.random on the final line is attempting to calculate with an empty or non-number value. It could be that the second number is somehow appearing as 0. The for loops you have near the end are a bit out of context. Mind explaining what they do and why they are there?

0
I got help from someone, they gave me this chunk of code, I didn't know how to make people have chance stats for being picked so they gave me this chunk... also, hmmm... should I replace the [#TopHat + 1] with [#TopHat + i]? KAAK82 16 — 10y
Ad

Answer this question