Getting random parts from folder in ServerStorage

I have a folder in ServerStorage where I am pulling parts out of it to clone into the workspace. However, I only want pull them out randomly.

Example:
ServerStorage.Objects has:
part1, part_top2, part_bottom3, part4, part5

How would I pull those parts out randomly?

for _, v in pairs(game.ServerStorage.Objects:GetChildren()) do
    partClone = v:Clone();
    v.Parent = game.workspace;
end

you could put the parts in a table | Roblox Creator Documentation and use math | Roblox Creator Documentation .random to select one item from the table.

1 Like
local Storage = game:GetService("ServerStorage")
local Objects = Storage.Objects
local Count = #Objects:GetChildren()

for _ = 1, Count do
	local Object = Objects[math.random(#Objects:GetChildren())]
	local Clone = Object:Clone()
	Object:Destroy()
	Clone.Parent = workspace
	task.wait(5)
end

If you don’t want to destroy the instances being cloned then you can simply clone the folder which is being cloned from.

2 Likes