Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Getting a Random Child? Please help quick?

Im trying to make this get a random gear and parent it to workspace. It didn't Parent itself to workspace. I checked the model and all gears remained.

math.randomseed(tick())

local Gears = game.ServerStorage.Gears:GetChildren()

local GearPick = math.random(Gears)
GearPick.Parent = workspace

1 answer

math.random requires a number, not a table...luckily you can just pick a random number based on the table size

math.randomseed(tick())

local Gears = game.ServerStorage.Gears:GetChildren()

local GearPick = Gears[math.random(1, #Gears)]
GearPick.Parent = game.Workspace

This discussion is preserved as it was. New answers, comments, and votes are closed.