Selecting every second studt

Hello developers.

I want to make it, so that every Second studt here in this demonstration gets selected clockwise. How would I do that? Using ipairs won’t achieve it.


I haven’t really tried as I do not know how to do that with the most optimization possible as the finished result will be a map that has to be loaded in so yeah.

Thanks to everyone who is able to help me with this.

You want something like this?

Screenshot 2024-05-19 182850

Basically, yeah. I just want to make a gauntlet where every 2 seconds every second part disappears.

Here is it:

local folder = script.Parent.TestParts -- folder
local children = folder:GetChildren() -- children

local function calculateAngle(center, part) -- function to calculate the angle between the part and the center
	local direction = (part.Position - center).Unit
	local angle = math.atan2(direction.Z, direction.X)
	return angle

local center =, 0, 0) -- center position

for _, part in ipairs(children) do
	center = center + part.Position
center = center / #children

print("Center position:", center)

-- Sort parts based on their angle from the center
table.sort(children, function(a, b)
	return calculateAngle(center, a) < calculateAngle(center, b)

-- Print the sorted parts for debugging
for i, part in ipairs(children) do
	print(i, part.Name, "Angle:", calculateAngle(center, part))

-- Function to hide every second part
local function hideEverySecondPart()
	for i = 2, #children, 2 do
		children[i].Transparency = 1
		children[i].CanCollide = false -- or destoy whatever u want

-- Main loop to hide parts every 2 seconds
while true do


Screenshot 2024-05-19 183419

(Parts will start dissapearing)

Screenshot 2024-05-19 183428

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.