Math.random interval empty even though there's items in the folder

So I’m making a random tool selector and each time I use math.random(1, #ToolsTable) on the tools folder, it just errors:

Context/code:

local Tools = Folder:GetChildren() -- Children of the tools folder
local ToolsTable = Tools
local selectedIndex = math.random(1, #ToolsTable) -- Line that errors

-- And yes, it is made like this further in the code:
-- ToolsTable[selectedIndex]

The folder:
image

The script location:
image

I think that the issue is is that the script loads faster then the folder, since the folder contains guns with tons of code. If it’s the case, how could I wait until the folder fully loads??

use something like:

repeat
    task.wait()
until #Folder:GetChildren() > 0

local Tools = Folder:GetChildren() -- Children of the tools folder
local ToolsTable = Tools
local selectedIndex = math.random(1, #ToolsTable) -- Line that errors

-- And yes, it is made like this further in the code:
-- ToolsTable[selectedIndex]
local Tools = Folder:GetChildren() -- Children of the tools folder

local selectedIndex = Tools[math.random(1, #Tools)]
print(selectedIndex)

Well.. you can’t do that after the error.

Edit: I put it after the folder is stated, and it prints the guns. Math.random still doesn’t work though

Are you sure there is more than one item in the folder?

Alternative code.
local Tools = Folder:GetChildren() -- Children of the tools folder

local random = Random.new()

local selectedIndex = Tools[random:NextInteger(1,#Tools)]

print(selectedIndex)

Ah that was it, math.random usually works with one item fine in my experiences.