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

Is there a more efficient way of getting a random part?

Asked by
bossay6 62
6 years ago

So basically, I want to know if there's a more efficient was of getting a random thing. Let's say i have 100 parts, and I want to get a random one out of all of them. I could do the math.random() method, but it would be tedious. Is there any other efficient way?

0
If you mean that you want a completely random part, since math.random() isn't completely random, try looking at this: https://devforum.roblox.com/t/a-random-feature/64517 steven73598233 75 — 6y
0
Ughhh why does this keep happening to me? My reputation is going down by the minute bossay6 62 — 6y
0
@bossay6. Question has been answered Axceed_Xlr 380 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago
-- Declaration Section 

local model = game:GetService("Workspace").Parts
local parts = model:GetChildren()

-- Output Section 

local randomInteger = math.random(#parts)
local randomPart = parts[randomInteger]
print (randomPart)
0
thanks! bossay6 62 — 6y
Ad

Answer this question