How do you make multiple models rotate at the same time?

Hello, I’m attempting to make a script that finds all models in a folder, and rotates them all simultaneously.
While this script does successfully rotate the parts, it does so one at a time.
How would I go about making the code rotate all the models at once?

I currently have the below code in a disabled script and call it when the models need to be rotated.
Again this works fine, but only moves the models one at a time.

Current code below.

-- Table Vars
Table = workspace.TowerSystems.LaunchTable
Water = workspace.TowerSystems.WaterSystem
Arms = Table.Arms

local clamps = {}
local function FindClamps(obj)
	for _, child in pairs(obj:GetChildren()) do
		if child:IsA("Model") then
			table.insert(clamps, child)
		end
		FindClamps(child)
	end
end
FindClamps(Arms)

local function OpenClamps()
	for _, clamp in pairs(clamps) do
		for i = 1, 25 do
			wait(0.005)
			clamp:SetPrimaryPartCFrame(clamp.PrimaryPart.CFrame * CFrame.Angles(math.rad(-2.2),0,0))
		end
	end
end

OpenClamps()

Your OpenClamps function will wait til the for loop is complete before moving onto the next model.
Using multi-threading, you are able to run all the for loops at once.

Table = workspace.TowerSystems.LaunchTable
Water = workspace.TowerSystems.WaterSystem
Arms = Table.Arms

local clamps = {}
local function FindClamps(obj)
	for _, child in pairs(obj:GetChildren()) do
		if child:IsA("Model") then
			table.insert(clamps, child)
		end
		FindClamps(child)
	end
end
FindClamps(Arms)

local function OpenClamp(model)
    for i = 1, 25 do
	wait(0.005)
	model:SetPrimaryPartCFrame(model.PrimaryPart.CFrame*CFrame.Angles(math.rad(-2.2),0,0))
	end
end
local function OpenClamps()
	for _, clamp in pairs(clamps) do
		coroutine.resume(coroutine.create(OpenClamp), clamp)
	end
end

OpenClamps()

This is what it looks like with that one minor change, of course with wooden houses instead of clamps.

1 Like