the wait() takes wayy too much time. And for some reason all the loops with wait() are not fluid. My game contains alot of Terrain but i have Content Streaming Enabled. The chunks are supposed to load in and load out, keeping the client memory low and allowing players with weaker devices to play.
Are you saying that your game is lagging, if so look for things that may lag it for instance random scripts with nothing in and humanoids lying around in the workspace. If not try bringing down the Content Streaming settings.
Hmmm, that is strange, it may either be a slow server or your internet / connection to the server as if you are using wait(), then it should not take ages.
When using wait() you shouldn’t expect it be right on time. You’re telling your script to wait for the given amount of time and then some extra until it can find a spot in the scheduler to continue running. Meaning the busier your scheduler gets the more likely you risk inaccurate times.
My best advice is to look for other methods of handling your loops and try to find spots where event based triggers can be used.
Yes the general principle is the more you call wait() in a period of time the more inaccurate it gets. So having 20 loops using it can really bog down your script performance.
If you really need a loop you can use RunService.Heartbeat:Wait(). But you should try and find ways to avoid loops in general.
local function WaitCustom(n)
local RunService = game:GetService("RunService")
n = n or 0.001
if n >= 1000 then n = 1000 end
if n <= 0.001 then n = 0.001 end
local Time = os.clock()
repeat
RunService.Heartbeat:Wait()
until (Time - os.clock()) >= n
end
This is called a “heartbeat wait”. I think it should perform better.
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:
Unless it is physics or camera related, don’t use renderstepped or stepped. Use Heartbeat.