How to get a random child from a folder?

Greetings
I’m having trouble with my script. I have a folder with different gears in it, and the player is supposed to get a random tool from this folder, but I have been adding a lot of gears lately and it’s too much work for my method of math.Random. so I was hoping for different and easier way of getting a random child from this folder!

thanks for the time.

math.Random will work fine. You just need to update it after any certain thing happened

local items = Gears:GetChildren()
local randomItem = items[math.random(1, #items)]

I see, I’ve been using math.Random in a non-efficient way.

thank you this is what I needed!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.