How would I make 1000+ parts move without lag?

Try and see if parallel luau works then. It will still lag, but it shouldn’t lag as much.

Wouldn’t that require a for loop? That’d just make it 10x worse right?

I’ve tried the AlignPosition. It works well, but the parts spin out of control. Is there a way to fix that and make it keep the same orientation?

looping through object isnt actually as bad as changing their positions physically imo

what i was suggesting was to split the objects into smaller groups and move a different group per frame

yes use it with alignorientation

That’d make it look a bit choppy. With all 1k+ parts, the script would have to go through 1k+ parts and try to make them move, which would probably put a lot of work on the server. It’s kind of the same situation still. Just more choppy.

What would this look like by the way?

Model:PivotTo(Model.WorldPivot+Vector3.new(0, 0.5 * Time, 0))
obviously this doesnt solve the problem but now the object will adjust after a fast or slow frame
however, you now have to tweak the increment because it will only move at .5 studs a second

The AlignOrientation isn’t working well. It still spins out of control.

AlignOrientation only controls the orientation of a part, as its name suggests. try using AlignPosition

Also, this worked kinda. (character limittttttt)

are all the parts going to the same position if so how often is this position changed by the server? it is better to always render movements and effects on the client not server if you can

this is 1k parts being moved to new position ever RenderStepped

here is the code put it in local script you can see how it runs

local NewFolder = Instance.new('Folder', workspace)

for i = 1, 1000 do 
	local Part = script.Part:Clone()
	Part.Parent = NewFolder
end

local PartsTable = NewFolder:GetChildren()

game["Run Service"].RenderStepped:Connect(function()
	local NewPosition = Vector3.new(math.random(-10,10),math.random(-10,10),math.random(-10,10))
	for _, part in ipairs(PartsTable) do
		part.Position = NewPosition
	end
end)

The parts are going to their positions, just + 0.5 studs on the Y axis. Like this:

part.Position = part.Position+Vector3.new(0, 0.5, 0)

I am using AlignPosition, but the parts spin out of control is what I’m saying. I need a way to keep that in check. It should continue to have its orientation that it started off with.

use Align Orientation with AlignPosition

How do I script it well? Here’s my current code of it.

Part.AlignOrientation.CFrame = Part.CFrame

that can work if the part is in the orientation at start, you only need to set that once unless there is a reason to change the orientation

just to show you how smooth this works with client control this is a game I made, this is 710 pets my client is controlling and rendering at one time


Hello, Your script seems to be running a calculation for each part in every frame, which can certainly cause lag when dealing with large numbers of parts.

To reduce the lag, you can use several strategies:

  1. Part Pooling

Pooling means reusing game objects, instead of creating new ones. This reduces the overhead of allocating and deallocating memory, which is an expensive operation in any programming language. If you can implement a pooling system for your parts, you should see a performance increase.

  1. Spatial Partitioning

Spatial partitioning is a technique used in game development to manage objects in a game scene. It’s especially useful when there are a large number of objects that need to be tracked and updated, but only a subset of those objects need to be processed at any one time. This could drastically reduce the number of calculations your game needs to perform per frame.

  1. Efficient Physics

If the physics in your game is causing the lag, you might need to consider whether every single part really needs a physics body. The fewer physics calculations your game engine has to make, the more efficiently it will run.

  1. Throttling Updates

Instead of updating every part in every frame, you could limit how often these updates occur. This can greatly reduce the burden on your game engine. Here’s an example of how you could implement this:

local FRAME_RATE = 1/30 -- 30 updates per second
local elapsed = 0

RunFunction = RunService.Heartbeat:Connect(function(deltaTime)
	elapsed = elapsed + deltaTime

	if elapsed >= FRAME_RATE then
		Model:PivotTo(Model.WorldPivot+Vector3.new(0, 0.5, 0))
		if (Model.WorldPivot.Position.Magnitude > Goal.Magnitude) then
			RunFunction:Disconnect()
		end
		elapsed = 0
	end
end)

In this script, updates will only occur 30 times per second, rather than once per frame. Depending on the frame rate, this could significantly reduce the number of updates.

4 Likes