Im trying to wait the delay but because of server lag the waits are a lot longer than they should be.
Current Code for wave system
local WaveContent = Waves.CalcWave(Wave.Value)
for _, WaveData in ipairs(WaveContent) do
local Choice = math.random(1, #WaveContent)
local WaveInfo = WaveContent[Choice]
for Clones=1,WaveInfo.Amount do
local Clone = game.ServerStorage.Bloons[WaveInfo.Bloon]:Clone()
Clone.Parent = workspace.Bloons
Clone:SetPrimaryPartCFrame(game.Workspace.Map.Start.CFrame + Vector3.new(0,1,0))
Clone.Runner.Disabled = false
local Money = 50 * Wave.Value / 2
RunService.Stepped:Wait(WaveContent.WaveDelay) -- There appears to be no wait at all
Wave.Value = Wave.Value + 1
RunService.Stepped:Wait(WaveContent.WaveDelay) does not seem to be waiting at all.
Any tips on using this and making this faster?
If you do RunService.Stepped:Wait() all you are doing is waiting for the physics before a frame to occur. To my trained eye, that is literally pointless as if as you said the game lags then you might wait a bit longer. If you have a lot to load before the frame and lots of physics need calculating then this function would slow dramatically.
You would be better just using wait() or nothing at all - you’ll see little difference in this function. If you have nothing it will just seem heavier.
If you want for it to delay until an event occurs then you should create a conditional loop until the arguments are met.
If you want for it to delay for a periodic time then simply do:
local start = tick()
delay = 5.23
repeat wait() until tick() - start >= delay
That way it waits a specific amount of time before continuing.
Here is a function that can replace wait() cause wait() does wait longer, and can wait even longer than needed depending on throttling conditions, which can make it wait a lot longer depending on how much you use it.
local function CustomWait(n)
n = n or 0
local DeltaTime = 0
DeltaTime = DeltaTime + RunService.HeartBeat:Wait()
until DeltaTime > n