Now before you get mad at me, usually I would use RenderStepped or some other event of RunService to calculate time or small yields, but since these are unusable I’ve come up with an almost bootleg solution using events that can be used on the server side. I really don’t want to use this because, to be frank, it seems stupid. But I don’t know of any other reliable waiting methods that can be ran on the server. If you do, please let me know so I can start using it. Or if you have any other methods that you think would work better, please feel free to share them with me and others.
local tService=game:GetService("TweenService")
local waitInt=game:GetService("ServerStorage"):WaitForChild("WaitInt")
local function myWait(n)
local tinfo=TweenInfo.new(n);local timeTween=tService:Create(waitInt,tinfo,{Value=n})
timeTween:Play(); timeTween.Completed:Wait()
end
--Ignore syntax or capitalization errors, I wrote this on the DevForum not in studio
This is the function I use. It waits until the time is almost up to actually start counting frames, since there’s an unacceptable processing time cost when you have 60 scripts calling rs.Heartbeat:Wait().
local rs = game:GetService("RunService")
function counterWait(t)
local startTime = tick()
local elapsed = tick() - startTime
local timeToCompletion = t - elapsed
while elapsed < t do
if timeToCompletion > 4 then
wait(1)
else
rs.Heartbeat:Wait()
end
elapsed = tick() - startTime
timeToCompletion = t - elapsed
end
end
I was under the impression that all runservice events that run each frame, Heartbeat, Stepped, RenderStepped, etc, only ran on the client side. Is this not the case?
No, because server can and does calculate physics for the unanchored parts they have the network ownership of too. So Heartbeat and Stepped events are useable on the server.
local function wait(n: number?) -- Better wait function
if not n or n == 0 then
return RunService.Heartbeat:Wait()
else
local timePassed = 0
while timePassed < n do
timePassed += RunService.Heartbeat:Wait()
end
return timePassed
end
end