Lag Optimization Tips Needed!

This usually happens when cloned parts are parented to workspace at the same time, I think you should just use a for I loop and parent the cloned parts one by one slowly and do a task.wait. (This isnt fast sadly)

Make Meshes instead of Parts, unions etc…

I have. It’s a script issue or something.

  1. Limit the number of parts in the Workspace at any one time. If possible, try to keep the number of spawned parts to a minimum.

  2. Avoid having too many scripts running at the same time. Be sure to delete any scripts that are no longer needed.

  3. Reduce the number of lights in the game. Lights can be a major source of lag and should be kept to a minimum.

  4. Reduce the number and complexity of textures used in the game. Textures can also be a major source of lag, so be sure to use only the necessary textures.

  5. Limit the number of sounds playing in the game. Sounds can also cause considerable lag, so be sure to keep them to a minimum.

  6. Optimize the scripts used in the game. Take a look at the code and try to see if you can find any ways to make the code run faster.

  7. Make sure all assets used in the game are optimized for performance. Try to use assets that are as small and efficient as possible.

  8. Use a server-side solution to reduce lag. If your game is hosted on a server, you can use a server-side solution like a CDN to reduce lag.

  9. Try running the game on a different platform. If you’re running your game on Roblox, try running it on a different game engine, such as Unity or Unreal Engine.

  10. Make sure you’re running the latest version of the game engine. If you’re running an older version of the game engine, you might be missing out on important optimizations.

  11. Try to avoid memory leaks.

  12. Try to use MeshParts instead of normal Parts.

1 Like

What speed is this script moving at?

The nice part of switching between using CFrame and Roblox physics is that you can adjust the “quality” of CFrames. If you’re running these CFrames every heartbeat (1/60th of a second) I suggest toning it down to 1/30th of a second and see if there’s a decrease in lag.

Sorry for such late response, I figured this topic died to be honest. The CFrame speed was at 1.5, or 2 I think. Also, I do not know how to use RunService, so I used a for loop.

All good, @baseparts above sent a RunService example that I think sums up how to use it really nicely. If you’re still up for optimizing your code, read below!

Can I see your code? I’m a bit confused on what this means.

local RunService = game:GetService("RunService")

local Buffer = 0

RunService.Heartbeat:Connect(function(DeltaTime)
	if (os.clock() - 1/15) - DeltaTime < Buffer then 
        -- Runs every 1/15th of a second. If the 1/15th of a second threshold hasn't been passed, it'll just return the heartbeat, which means nothing past it will run.
        -- You can change 15 to any number. If you change it to 60, it'll be performing like a normal heartbeat. As heartbeats only run every 1/60th of a second.
        -- If you change it to 30, it'll look similar to 60 but if you focus on the CFrames they will look ever so slightly "choppy"
        -- If you change it to 15, which I recommend only if you have a lot of parts, it'll look choppy but will still look somewhat normal.
        -- Obviously you don't have to stick to these numbers, but they're here as a guide.
		return
	else
        -- Everytime 1/15th of a second has been reached, it will reset the clock and wait for the next 1/15th of a second.
		Buffer = os.clock()
	end
	
	-- Do code with moving CFrames here.
end)

Buffers are important in this case when you don’t need to run it 60 times a second, which I doubt you need to unless you want extremely precise hitboxes or calculations for whatever you’re doing. Using this code and setting it to 1/30th of a second should optimize it well enough, as it’s basically cutting the workload in half.

If you could post your code I could try to package it all nicely together.

This code was already at 29, but here it is again.

local Speed = script.Speed

for i = 1, 250 do
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, Speed.Value)
wait(0.025)
end

game.Debris:AddItem(script.Parent, 0)

I’m a little late to the party but…

You could use a lag reduction service such as StreamX:

You can check the part counter.

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