New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Still have questions? Join our Discord server and get real time help.
Log in to vote

math.random error (interval is empty)?

Asked by 5 months ago

I am trying to make a script that gets a random "Chunk" which is a group/model in a folder in server storage, The problem is that when it tries to pick a random "Chunk" it has this error code: Workspace.ObbyGenerator:10: bad argument #2 to 'random' (interval is empty)

Here is the code:

local ChunkSize = 144
local ChunkCounter = 0
local Chunks = {}


function CreateNewChunk()
    local ChunkCoordinate = ChunkSize * ChunkCounter
    local ChunkPicked = game.ServerStorage:FindFirstChild(Chunks[math.random(1, #Chunks)]):Clone()
    ChunkPicked.Parent = game.Workspace.Obby
    ChunkPicked:MoveTo( + 144, 0.5, 0))
    ChunkCounter = ChunkCounter + 1

local Obby ="Model", game.Workspace)
    Obby.Name = "Obby"
local firsthundredchunks = 100
    firsthundredchunks = firsthundredchunks - 1
    ChunkCounter = ChunkCounter + 1
until firsthundredchunks <= 0

while wait(3) do
    ChunkCounter = ChunkCounter + 1

Thank you to anyone who can fix the problem :)

1 answer

Log in to vote
Answered by
royaltoe 4600 Moderation Voter Community Moderator
5 months ago

Chunks is an empty table. You don't add to the table anywhere in your code so your math.random interval is 1,0 since the number of chunks is zero. this doesn't make sense to the computer.

Thank You :) BriskyDev 4 — 5mo
Sure thing. What were you trying to do anyway? Was chunks supposed to be all the items or was chunks supposed to be a reference to all the chunk models? royaltoe 4600 — 5mo

Answer this question