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
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
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.
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.
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.
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.
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