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

How do I pick a random brick?

Asked by
Zerio920 285 Moderation Voter
10 years ago

What kind of function would let me pick a random brick from a model?

2 answers

Log in to vote
2
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
10 years ago

Well you would have to get a table of all the children in the model, then use math.random on the table to get the random part.

Example;

AllDehParts = ModelOfParts:GetChildren() --Made a table of the parts

DatOnePart = (AllDehParts[math.random(1,#AllDehParts)])

--Use math.random on the table to get the random part, the arguments are just saying choose from 1 out of the total number there is, I know it looks confusing but it's not when you get the just of it.

Any questions I'll be happy to answer(:

-Goulstem

Ad
Log in to vote
0
Answered by 10 years ago

This script will get a random child from 'Model':

local model = game.Workspace.Model
local ranPart = model:GetChildren()[math.random(1,#model:GetChildren())]

Much simpler :P

Answer this question