Error with getting a random item from a folder

For some reason, its searching the number instead of getting the item from the folder.
image

Here’s a portion of the script:

local GunsFolder = repStor:WaitForChild("Guns")
local items = GunsFolder:GetChildren()


print("start")
local gunSelected = GunsFolder[math.random(1,#items)]:Clone()

Try printing #items and see what it gives you

I made it print the items table and the amount, everything is as it should be:
image

GunsFolder is an Instance, did you mean to index the item value?

local gunSelected = items[math.random(#items)]:Clone()

You’re trying to index an item in the GunsFolder called “8” when you do GunsFolder[math. bla bla bla
Try to index the item from the items table, not from the GunsFolder object.

local gunSelected = items[math.random(1,#items)]:Clone()
1 Like