Wait() taking too much time

For the time issue you could use os.time or tick to get the exact second

Avoid using RenderStepped unless it is something very very important.
RenderStepped blocks rendering until the connected function is completed. So if you put anything demanding in there, your game will fall apart.

Here is a chart by rogchamp: image

Unless it is physics or camera related, don’t use renderstepped or stepped. Use Heartbeat.

1 Like

maybe use RunService.Heartbeat:Wait()
here’s my fastwait module

local RunService = game:GetService('RunService')

w = function(d)
	local t = d or 0
	local n = 0
	while RunService.Heartbeat:Wait() do
		if n < t then
			n += 1
		else
			break
		end
	end
	return
end

return w
1 Like

can i basically replace all the wait() with RunService.Heartbeat:Wait() ?

Heartbeat is much faster (for me), but you can wear my module instead

Nope

  • RunService.Heartbeat:Wait()

changed nothing. This is a very weird issue. The Clients do no lag and the gameplay is fluid. However the server is slow for some reason

I have an idea, why this is happening.

  • my game contains alot of Terrain and Water Mass. The map is stored on the server.

My game has Content Streaming Enabled, chunks load and load out for the Client depending on their position.

But thats client sided only

That explains why the server lags and not the clients. That explains why the GUI local scripts dont lag and normal scripts lag. The Map is wayyy too big for the Server to handle. I will be adapting it soon to solve this issue.

Edit: Here is a quick preview of my underwater terrain

https://gyazo.com/80000d8ec87c72a202abc7d0d4901848

then it is totaly your internet lol.

It is definitely not. I have a 10-linear Fiber internet, that is not the issue.
I think im right. It is the map size

yes im right, your big map is making you lagging.

I really don’t think that’s the issue.
The server does not render anything so a bunch of parts is not an issue for the server unless they are all unanchored and being updated by the physics engine. Terrain itself is also highly optimised.
My guess would be that either one of your scripts (or a script you downloaded) is doing something VERY demanding on either RunService.Heartbeat or RunService.Stepped.

Obviously I can’t give you an accurate report because I have no way of knowing but since Heartbeat:Wait() did not fix it then that would be my guess.

There is a way for you to get a more accurate report, and that is via the developer console.
Hop into an actual version of your game (not inside Studio, preferably in a normal server full of players to show real world scenarios).
Then click on ServerJobs and look for anything that is taking a crazy amount of “DutyCycle”. Also check the “Steps per second” and make sure they are all running at 60 (give or take a little bit).

If nothing there is telling you what’s wrong or you can’t understand it then move on to the microprofiler.
Click on the MicroProfiler tab and then inside the ServerProfiler section set the Frames per Second to 60 and Seconds to Record to whatever value you want which is above 1 but below 5.
Click start recording and wait.
Once it’s done, it’ll give you a file path to a .html file. Navigate there in Windows Explorer and open the .html file with a web browser.

That will show you very detailed analytics so you can use that to diagnose your issue. If you can’t understand it then you can send it to me and I’ll try my best to tell you what’s happening with it.

This will 100% show you the issue. It might be something like Replicator made by Roblox which you cannot fix (in which case the issue is your map) or it might show you a misbehaving script.

2 Likes

Alright thanks for your reply i will follow the steps

In the “Server Jobs” nothing too crazy going on. I’m not sure what is considered alot.

  • Most demanding tasks are “WaitingScriptJob” with 0.67% and “Simulation” with 0.2%

Alarming:
All my “Steps Per Second” are at 11.3, far from 60

Not sure what is going on

i am already using Client-Side chunk management with “Content Streaming”
All the mesh render precision is set to “Automatic”

1 Like

Sounds like your chunk manager is lagging a bit (since that script has to wait, process and again, etc.). Maybe you should test the manager in an empty place to see what it does. Also use RunService.Heartbeat as mentioned by others. Wait is usually a bit meh.

1 Like

RunService.HeartBeat had no impact, i tried. On a blank place simulation as around 0.05% and WaitingScriptJob is at 0.0008%
Steps per Second is at 60, stable
Yes huge diffirence.

1 Like

Please do some research before making a post.

1 Like

Of course i read that thread before making this post. I optimised my scripts. Used RunService.Heartbeat, turned my while true do or any other loops into waiting functions. Removed useless script weight and some parts of my Terrain map. All the scripts that are left are very important for the game to function.
I simply can not find any other explanation than my Terrain map with huge water mass being way too big. This post has been made a couple of days ago and yes, research has been done

The server has to load everything for all clients, so even if you have StreamingEnabled turned on it will not help. I would recommend just optimizing your scripts.

This is the most accurate & best alternate of Wait() function:

local runService = game:GetService("RunService")
fastWait = function(t)
	local d = 0
	while d < t do
		d = d + runService.RenderStepped:Wait()
	end
end

Here is a module you can add to your Toolbox using os.clock() to ensure you are measuring your time correctly. Works exactly like wait() already works as you can run wait() with no parameters.
https://www.roblox.com/library/6680939762/Wait