Local Loop controlling many parts at the same time

Hiwi, thanks for reading!

I want to spin many parts at the same time. The parts were created by a local script.
Im trying to spin them by CFrame on its own axis. The spin loop, should be controlled by local script using RenderStepped.
What do I use? A local script module? do I tag the parts? I just create a table and loop it inside the render loop?

Actually I dont know how the loop would look like… Feeding a table of parts constantly?
isnt that exesive or something?
quick example: (100 parts loop, changing CFrame, and on Render speed?)

local array = {
	part, part, part ... -- Imagine these are 100 parts

while true do
	for _, i in pairs(array) do
		i.CFrame = i.CFrame * CFrame.Angles(math.rad(0),math.rad(0),math.rad(1))


How do I use a local script module for this task? Helps in any way?.. Im lost tbh… Any advice? Thank you for ut time :3

It doesn’t work because “part” does not have a value and is not equal to a Part object.
Also, another way to do this is maybe put all the parts in a model and loop through them using “Get Children”
ALSO: Is the variable that sets “part” to something in another script? Well, if it is, that’s why it doesn’t work.

1 Like

Yup, well everything is well connected… Perfectly works. That is just a quick example…
Its about the questions I made, the script is just to ask and show if feeding a table of 100 parts is excesive or not by changing each one their CFrame on RenderSteep wait.

Just a procedure, Im asking

It doesn’t work due to,

  1. An end after RenderStepped:Wait()
  2. It does the following: rotate every part X amount and wait, then rotate again.

Instead I’d do the following:

local array = {}

for _, child in pairs(array) do
        while wait() do
            child.CFrame = child.CFrame * CFrame.Angles(math.rad(0),math.rad(0),math.rad(1))

What it does here is:

  1. Go through the array,
  2. spawn a function which doesn’t interver with the for-loop
  3. while loop,
  4. Rotate the parts.

Instead a great option would be using HingeConstraints, as when you stand on one of these rotating parts the player’s character won’t rotate with it.

1 Like

Hi. I would do this to rotate many parts through your CFrame on the client side:

local degreesPerSecond = 0.5

local function onRenderStep(deltaTime)
	for _, part in someTable do
		part.CFrame *= CFrame.Angles(0, deltaTime * degreesPerSecond, 0) 


The modules have two main objectives: to make the code more tidy or to reuse code. So ask yourself, is my code so messy that I have trouble reading it? or, can I use this somewhere else?

Using CollectionService:GetTagged or GetChildren are probably more expensive than simply using a table. Since you are creating the parts on the client side, it is best to save your references in a table and use it in RunService.RenderStepped. This depends on whether you really have performance issues. The only way to know is to test it in your game and not in a simple experiment.

It is typical to use loops or custom functions within RunService.RenderStepped. Again, you should only do something if it really causes problems in your game. Well, a game never stays constant and is always growing. At first there may not be problems, but after several updates maybe there are, so that’s when you should do something to improve the situation.

If you have performance problems with the code above, there are several alternatives that are more sophisticated and perhaps more difficult to implement, for example spinning by groups or only spinning the parts that the player can see. Worrying prematurely about performance can waste your valuable time.

Good Luck


Im really sorry for making all you guys wasting your time. I mean. I already have a functional module changing the CFrame. And its working fine, no lag or anything. I just wanna know whats the best approach, cause Im very worried to make devices making a loop spinning hundreds of parts in a game.

Your answer makes me feel better, but… feeding a table with maybe 500 parts, still ok? All those parts created by client side in a table. And a loop changing its CFrame each RenderStep? is not bad?

I tried this by Motors, in server or local, by CFrame (i like this more cause theres no physics affecting the motor) managing them from server and local (different tests) … I mean it works… but I kinda feel this wont work when I add more parts on client devices…

Again sorry for wasting ur time guys u ,u…

Nope hinge constraints is causing me lots of problems…

This is a giant path randomly created, reading box boundaries in order to make turns and create a weird paths… Paths eventually random gets a spining rotation of the “room”… I tried hinge motors, but, when “rooms” get created, it acts very weird when placing the root of the model in the next position to create the path (like smoothly/slow floating on thin air) reaching their position… So I disabled the motors, and after placing them, activate the motors again and deleting the weld… Then, when a motor is spinning, lots of problems with physics. If its a big room holding characters spinning by motors, the motor get stucked, no matter if the physics are only solved by the client… and the game looks weird too by many different rotations while playing on a team…
anyway… thank u for ur answer, yup that loop works too :3

It sounds like you’re thinking about the most extreme case. I can’t imagine a game where there are 500 parts, for example coins, rotating at the same time. But this is my personal point of view.

As there are many devices, it is not possible to know in advance if this will work well in all of them or even if it will work at all. Something you could do is look for a game that has done something similar to what you want to achieve, try it on some devices, and try to replicate its method.

Anyway there are more sophisticated alternatives that you could implement depending on the device (this is what pop games do). It’s difficult or impossible to do something general that works well everywhere, or so I think.


maybe yes, Im exagerating… Just a few rooms that should rotate, killing stuff that should rotate etc…
Probably keeping low those parts would be the better.

I never tested before how to spawn the world by “chunks”… Like that would be better to try, if Im trying to move many stuff for only “2 clients team”, I tried many ways, no problems but, idk…

I tried build a random path made of rooms and corridors by script, adding behaviour to rooms, and random spinning stuff that kills… I can set how many rooms I want before being builded, and random spinning stuff with welded parts that kills on touch spawn in those rooms.

Everytime I test all the fused stuff, on my PC works perfectly normal, not even a little lag… but… devices, low gamma devices… I better change my mind and make more experiments. Thank you so much for ur help!
I gotta think a lot… cause im very confused…