Hey there! My question is, Is there any other way to do this? It does the work but i feel it can be a little resource consuming.
Edit: I am doing a notification system where if you hold said notification, The timer will stop until unhovered. So for example if the notification has a length of 4 and you hold when the timer is 2, The timer will persist at 2 until the notification is unhovered.
--// While the user hovers the notifications,
--// the timer will stop there and will continue once the mouse leaves.
local LeftTime = data.Length or 5
local Holding = false
local Interval = 0.05
repeat
if not Holding then
LeftTime -= Interval
end
task.wait(Interval)
until LeftTime <= 0
Majority of the code is not here for privacy reasons
local endTime = tick() + (data.Length or 5)
local paused = false
local pauseStart = 0
local totalPaused = 0
while true do
if paused then
pauseStart = pauseStart == 0 and tick() or pauseStart
else
if pauseStart > 0 then
totalPaused += tick() - pauseStart
pauseStart = 0
end
end
if tick() - totalPaused >= endTime then
break
end
task.wait(0.1)
end
--!strict
--!optimize 2
--// While the user hovers the notifications,
--// the timer will stop there and will continue once the mouse leaves.
local RunService = game:GetService("RunService")
local Heartbeat = RunService.Heartbeat
local WAIT = Heartbeat.Wait
local TimerEnds:number = os.clock() + 30 --30 seconds
while os.clock()<TimerEnds do
--do stuff
WAIT(Heartbeat)
end
--Debounce ended
Don’t get overwhelmed with
local Heartbeat = RunService.Heartbeat
local WAIT = Heartbeat.Wait
Thanks!!! I was scared of burning someone’s computer with lots of notifications. ( Consider both of your replies as a solution, i cant put more than one D: )