How can I make this code less laggy?

Hi. I have this code here that’s a bit laggy. How can I make it simple for the server to run?

  1. What do you want to achieve? Less laggy script.

  2. What is the issue? Well, the title in a sense. Laggy script.

  3. What solutions have you tried so far? Well, I’m not exactly sure what to try. I’ve tried TweenService, but it still kind of lags.

Any ways I can make this code run smoothly?

local Part = script.Parent

for i = 1, 250 do
     Part.CFrame = Part.CFrame * CFrame.new(0, 0, 2)
     task.wait()
end

TweenService should have no lag at all, and this script you made shouldn’t either. Maybe something else is causing apparent lag, like maybe the part is unanchored?

3 Likes

Try making a variable for CFrame and CFrame.new because it’s easier for the server to take stored data other than getting globaly stored, if this didn’t work anyways it’s probably another issue and not the script it self

Like this?:

local Frame = CFrame
local NewFrame = CFrame.new(0, 0, 2)

The parts are anchored, so that’s not the issue.

Can you show the parts in a video?

Yes, Your script is fine , if this didn’t work then that’s some other issue

Okay sure. No problem.
(For the character stuffffffffff)

I’ll try your idea too.
(CHARACTERSSSSSSS)

it will be laggy because there is delay between the client and server, also the server runs at a lower fps than the client (most of the time)

This is not very accurate. The server doesn’t “run at a lower fps”. It’s the server. If anything it’s part of a powerful supercomputer somewhere in the Roblox server room. It doesn’t even have “fps” because it doesn’t do any simulations for itself. It simply just replicates states inside of itself to other clients. If anything, the client would have a lower fps than the server.

There is a small possibly that script could have lag, because you’re changing the property of an instance, every frame, literally every frame. So maybe, but it could just be an illusion, because there is no smooth movement between positions, it’s not lagging, just moving really fast.

Have you tried using a wait such as deltatime? Deltatime only works with RunService. If im pretty sure, deltatime is used to calculate FPS and could be useful to end slow and laggy scripts

1 Like

Sounds like this is a server-script, the server can skip some frames at times because the server has different tasks to deal with, try running it on the client-side instead, that should not lag or skip frames.

why are you making this in the server ?

what do you mean it doesn’t do any simulations

Which is what I’m saying. It doesn’t. It doesn’t have a framerate at all. There is no screen that shows what’s happening in game on the server. You’re giving out invalid information.

it is true that roblox servers do not render the graphics. However, they will still run a simulation of the world which will run a certain frequency otherwise how would spacial query API’s , such as raycasting , work on the server?

Here’s all I’m trying to say. If hypothetically the server was a player, and it could join games, there would be absolutely no way it would have a lower “frame rate” than the average player in the game. The server is a SUPERCOMPUTER. It is naturally more computationally effective than your average school computer. The server doesn’t or WOULDN’T have a lower rate than the client.

the server can in fact have a lower rate than a client if it is being loaded with heavy computations.

So sorry for such late replies. I had to do something all of a sudden. And sure I’ll try RunService, it was recommended to me before, but another person told me it didn’t reduce lag. So… I’ll try it I guess.