Alternatives to 200+ Client Tweens

I currently have a game where roughly 200 tweens played on the client run almost simultaneously, which I believe is the source of lag + loading issues.

As I was searching for an alternative solution, I came across this game which seemed to not use tweens for the dish movement. It also seems to be distance based, so it seems like the movement is handled every frame on the client, however, I may be wrong.

It would be wonderful if you could tell me what kind of the system the aforementioned game is using for the movement of the dishes. If there are any other methods, please let me know.

2 Likes

most of my tweens i do on the server for computing power, it also makes it so that other players can see whats being interacted with

1 Like

don’t tween on the server, it puts unnecessary strain on the server which can be put into other resources instead, and appears at like 30fps or less to clients

instead, use a remote event (can be unreliable depending on your use case) that fires to clients that’ll reasonably be able to see the tween

thanks

30 limit thanks for the info tho

1 Like

Do you know any alternatives to client sided tweens? The game I linked at the top seems to be using a different method. Any ideas as to how to achieve that?

Playing tweens shouldnt cause much lag if they are played on client, try to reduce the amount of unnecessary tweens. Alot of games does use RunService loops to move object per frame, mostly for lerping and springs

Would using RunService to update the position of an object every frame on the client be preferable? And is this the method the game linked at the top is using?

for some cases e.g constantly moving a object in certain direction with set force, updating position per frame is preferred. I dont know what method the game use, it is possible that they use mix of tweens, lerps and per frame updating

What do you mean by a mix of tweens and per frame updating?

They possibly use tweens for ui animations etc and update moving object e.g the dishes on the conveyer belt by runservice loops

My bad, I should have been more specific with my question. I am specifically talking about 200+ client tweens for models. I essentially want to move 200+ models simultaneously.

So if I do move the dishes with RunService, do I do it on the server or client? How do I make sure the movement is synced for all players if it is handled on the client?

do it on the client. Use a remote event to tell all clients at the same time to play a certain animation e.g

RemoteEvent.OnClientEvent:Connect(function(obj)
    Runservice.RenderStepped --run service loop
       --update position
end)

I dont recommend to always create a run service loop when OnClientEvent is fired because it can take huge amounts of memory, instead put the object in a table and use a separate Runservice loop to loop through the table and then update objects position

i’ll check it out in a bit once i get home but one neat strategy is to use mover constraints and motor6ds, they can occasionally be unstable but they can also be a viable alternative occasionally

edit: seems like they’re all being pivoted to manually and not tweened, while usually i’d expect this to be lerped or something the fact that they all turn around on corners leads me to believe there’s more going on here
i’d also assume that if you’re not looking at them nothing’s calculated (view-frustum culling) to save on performance since i’m seeing the camera’s cframe being accessed too, instead of using raycasts or Camera:GetPartsObscuringTarget() it seems to be manually calculated as well

If you need more customization (distance checks, variable update rate, etc.), doing your own linear interpolation is probably best.

Depends what you want to do, but if you wish to use items on a conveyor you probably want them to have a constant speed. Formula for speed is:

v=dx/dt, with v being speed, dx being the difference in distance and dt being the difference in time.

Example for 5 studs/s:
Movement amount per DeltaTime: 5*dt studs movement.

DeltaTime is usually the frame time (get it from a RunService loop). If you use variable update time, your DeltaTime is the time passed in between two updates. So the time passed since the last update as you’re applying the new movement.

The manual method is more work but it’s more modular if you want to have variable update rate based on distance. You can even remove far away models, and still keep them moving in logic so they’ll reappear once close.

Keep in mind you should optimize the model you’re moving around. Keep it as simple as possible for the best performance.

Thank you very much for your reply. I will take a look into those.
Could you take a look at my game and do the same analysis? I have been getting many reports of the game being laggy and taking time for it to load. I am not exactly sure what the source of the problem is.

1 Like

from what i’m seeing here in a microprofiler dump i don’t think the tweens themselves are the issue, i think it’s coming from the billboardguis attached to them all since i’m seeing an unusual amount of ui activity

interestingly the microprofiler graph is blue instead of orange here which apparently signals a rendering bottleneck, it’s spending a while waiting for the gpu to get going

image

looking further i noticed that i was getting major frame drops when moving the camera so i suspected it was the gui billboards, i got a dump of the profiler and it confirmed my suspicions of ui stuff lagging behind

image

now for a potential solution; a super effective one would be to make the billboards only appear when the camera’s like 15-25 studs away so it doesn’t have to render so much
BillboardGui includes a MaxDistance property however by default it’s set to infinity, so reducing it to a reasonable amount should not only fix most of the performance issues but also make the game look a lot cleaner

tldr: microprofiler suggests it’s actually the billboards that are causing performance issues, BillboardGui.MaxDistance should solve your performance issues

Thank you so much for your detailed analysis. I would have never realized without you pointing it out.

I just went through all of the SurfaceGui and BillboardGui and it seems like the initial loading has improved. I just published this change to the game(version 1.33). If possible, it would be great if you could confirm this performance improvement on your end as well.

1 Like

seems to work great, i’m no longer getting massive performance drops when moving my camera around (40-50fps → 80-90fps)

I am glad to hear that, I really appreciate your help.

1 Like