Randomized prop placement help

helo, i want to procedurally place window frames in a certain area. this is because there are two types of window frames, opened and closed. i currently am able to place each window frame, but i am not sure how to go about randomizing it. here is my code.

for i, v in ipairs(workspace.frames:GetChildren()) do
	for i2, v2 in ipairs(workspace.placements:GetChildren()) do
		local v_clone = v:Clone()
		
		v_clone:SetPrimaryPartCFrame(v2.CFrame)
		v_clone.PrimaryPart = nil -- property, not child
		v_clone.primaryPart:Destroy() -- child named "primaryPart" is now deemed useless
		v_clone.Parent = workspace
	end
end

here is hierarchy
image

what this currently does is place both opened and closed frames in each placement, which is the issue.

the script is cloning all the frames, and putting it in all the placements, delete the second for loop and just pick a random placement in the folder

so it would be

for i, v in ipairs(workspace.frames:GetChildren()) do
      local v_clone = v:Clone()
      v_clone.CFrame = workspace.placements:GetChildren()[math.random(1,     #workspace.placements:GetChildren())


end

not sure if this is the best way to do it but i decided to just do this

local function doitbro(part, v)
	part:SetPrimaryPartCFrame(v.CFrame)
	part.PrimaryPart = nil
	part.primaryPart:Destroy()
	part.Parent = workspace
end

for i, v in ipairs(workspace.placements:GetChildren()) do
	if math.random(2) == 1 then
		doitbro(workspace.frames.frame_closed:Clone(), v)
	else
		doitbro(workspace.frames.frame_opened:Clone(), v)
	end
end

ill check this one out, it looks much better than mine

this is just an example, I typed it in on my device so it might not work

real script would be like

for i, v in ipairs(workspace.frames:GetChildren()) do
	local v_clone = v:Clone()

	v_clone:SetPrimaryPartCFrame(workspace.placements:GetChildren()[math.random(1, #workspace.placements:GetChildren())])
	v_clone.PrimaryPart = nil -- property, not child
	v_clone.primaryPart:Destroy() -- child named "primaryPart" is now deemed useless
	v_clone.Parent = workspace
end

i think i will just stick with my script because yours isn’t doing it all at once and it is sometimes rechoosing the same cframe which will make multiple frames overlap each other. thanks anyway

did the real script i posted above not work also?

it isn’t filling all placements because the loop ends when it hits the final child, which there are only two of. the reason why mine fills all placements is because it is looping through the placement folder. it also isn’t overlapping because the child has already been iterated.

okay, you just need to alter the script a bit and it’ll work