How can I use :Clone() multiple times without duplicates?

as you can see, when I spawn 10 random stages, I get duplicates
image

here is my code

for example, if the math.random() chooses 5, how can I get it to not chose 5 again?
thanks.

You could add all the stages to an array and remove each stage after it is selected:

local tempStorage = script.Stages:GetChildren()
for count = 0, num_of_stages do
	local index = math.random(#tempStorage)
	local stage = table.remove(tempStorage, index)
	stage.Parent = folder
	stage:MoveTo(workspace.Spawn.PrimaryPart.Position + Vector3.new(0, height, 0)
	height = height + 20
end
2 Likes

had to make some changes, but thanks, this worked.