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:
The script location:
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??
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]
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)