Hi, I’m making a dialogue system using the new property called MaxVisibleGraphemes, I use a for loop to change the MaxVisibleGraphemes, I also have to use a ```wait`` there. I can’t really use a custom wait since it’ll depend on the frames of the client if we talk about using RunService for it. That’s my question, and I’ve some code:
for ind = 1, #dialogue, 1 do
dialogueLabel.MaxVisibleGraphemes = ind
wait(maxDialogueWaitTime)
end
Is it ok to use Roblox wait here?
Help is appreciated
Personally, instead of using wait() I use my own custom wait function, wait() has been known to cause performance issues and not perform well, @RFL890 explained.
So does wait(). The only way to “guarantee” a delay will be for exactly x seconds is a busy-wait, like this:
local function busywait(x)
local finish = os.clock() + x
while os.clock() < finish do end
return
end
… which has major performance concerns. You can use deltaTime, which is passed to all the RunService events, if you want to make more characters show up based on real-time rather than a number of frames. The change will only display on different frames anyways, so there’s no reason to isolate the two.
Also, sorry for bumping in here, but here’s a better wait function which uses RunService:
local function CWait(n)
n = n or 0.0001
if n >= 1000 then n = 1000 end; if n <= 0.0001 then n = 0.0001 end;
local runService = game:FindService("RunService")
local Time = os.clock()
repeat runService.Heartbeat:Wait() until (os.clock() - Time) >= n
return true
end
I tested it, and RunService Heartbeat wait had an Avg delay of 1e-07 seconds, and wait() had a delay of 1e-06 seconds. Or 0.000001 compared to 0.0000001 seconds.