Still have questions? Join our Discord server and get real time help.
0

# How do you find a part using math.random?

I'm trying to find a certain block out of 3 blocks, using math.random

local FolderForParts = game.Workspace.Folder
local PartNumber = math.random(1,3) -- 3 Blocks in folder
local Part =                --Finds the part


The part names (just keeping it simple): Part1 Part2 Part3

0

You need to get the number of the part

local FolderForParts = game.Workspace.Folder
local PartNumber = math.random(1,#FolderForParts:GetChildren())
local Part = FolderForParts:WaitForChild("Part".. tostring(partNumber))


This script transforms the selected number into a string and gets the selected part in the folder. P.S: With this script you can put as many parts as you want as long as they are numbered

0

I think this is what you want.

local FolderForParts = game.Workspace.Folder:GetChildren() -- make a table of parts
local PartNumber = math.random(1,#FolderForParts) -- 1 through length of table
local Part = FolderForParts[PartNumber] -- reference chosen part

print(Part.Name)

0
or FolderForParts:FindFirstChild('Folder' .. tostring(PartNumber)) if you want the naming and number to be consistent User#26471 0 — 6mo
0
Also a fine way to go about it, but lets keep it simple if hes unsure how to do it in the first place! DinozCreates 748 — 6mo