What increases the wait time on my client in my own game?

Hi currently wondering what could be the issue to increasing wait time or client latency.
I have currently “fixed” some of the issue by bandaging it with a custom wait time module.

So I had used wait() before and noticed over time it would start to take a lot longer for things to process after using different abilities within my game and my effects fireallclients and you do not make other client’s get this client latency.

Right now how my move works is
local script > fires to server > finds server skillmodule > finds fx clientmodule > fires to allclients

When you use the same ability over and over again it does not create client latency however if you use different skills it starts to create client latency extending wait time. I have checked for memory leaks and garbage collected everything I can.

When you RESET/OR DIE all the client latency dissapears? Anyone have an idea what the issue may be?

It’s possible that your roblox has a memory leak. Try asking your friends, or other users, to see if they also encounter the issue.

and also, remember to use game:GetService(“RunService”).Heartbeat:Wait() for serversided loops, and game:GetService(“RunService”).RenderStepped:Wait() for localscript loops.

They do encounter the issue, my effects are client sided and fired to all clients and does not cause this latency to other players however it is only when you as an individual client use different abilities.
And I have already used those wait’s.

Again, make sure you use The runservices above for waits. wait() is not enough.

Also use coroutine above every singe event statement, this will create a sandbox (basically a new script) in one script. Meaning, you can run multiable instances of this and not just one instance.

I already do all of this i’ve pretty much optimized my game pretty well this is the one issue and can’t to seem to locate why regular wait(ANYAMOUNTOFTIME) is extended

Its not a bug, it’s because the client is under 60 FPS. And game:GetService(“RunService”).Heartbeat:Wait() (for client) will sync the framerate with the wait time.

If you seem to know that your game is optimized, doughtly, having poor performance. Try your own stuff, and research it.

1 Like

What makes the client run under 60fps? It stays laggy until after I reset then the game will run normally again as in the client side, the server side is 100% fine.

I’m talking about ALL client effects slowng down.

Each frame, Roblox resumes threads that have called wait. If these threads are taking a long time to resume (ie they’re doing a lot of work, or there’s just a lot of them), it may prematurely stop resuming them on that frame, so the next frame will take over. This causes your calls to wait() to take longer and longer, because the list of threads to be resumed on any one frame may be snotted up.

Furthermore, spawn and delay also use this same mechanic, and it’s for this reason you should avoid them. @evaera wrote a great article on this topic, and I highly recommend you use her Promises library.

As @Lakodex suggested, you can adhere your code to Roblox’s task scheduler loop by using the various RunService events. However, you should not haphazardly use Heartbeat for server scripts and RenderStepped for client scripts - you should use that task scheduler article I linked to decide which is the best to use.

Maybe you should sniff around your code for any places where you might be wait()-ing on a loop too much, or unexpectedly using functions which are delaying things, like invoking BindableFunction and RemoteFunction.

2 Likes

wait() is old. It is based off of the 30FPS version of Roblox. You will want to use game.RunService.RenderStepped:Wait() for Client side, and game.RunService.Heartbeat:Wait() for server side, along with os.clock().

1 Like

You’re 100% correct with those first two sentences, but really off with everything after that.

A lot of work went into the Task Scheduler article to help inform developers on what API to use for their frame-by-frame code; do not reduce it to just RenderStepped for client, Heartbeat for server. That’s really misleading advice. Furthermore, os.clock() is used for benchmarking and not keeping track of game time.

1 Like

Oh ok. Would I use os.time then?

local RS = game:GetService("RunService")

local function Wait(Time)
    local T1 = os.clock()
    repeat RS.Heartbeat:Wait()
    until os.clock() - T1 >= Time
end