Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Getting a Random Child? Please help quick?

Asked by 6 years ago

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

Log in to vote
1
Answered by
Vulkarin 581 Moderation Voter
6 years ago

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
Ad

Answer this question