Alright, I could either be super tired and might be an easy fix or I am struggling internally.
While creating a queue system for Discord webhooks, the wait for the cooldown doesn’t work. I tried changing it with ticks, delays, and all that. Removing the wait entirely fixes it… but I need the wait; so it doesn’t potentially spam Discord webhooks requests. I check the breaks, it ain’t those either. Used Heartbeat and While Loop, both ended with this same problem.
I know there are other solutions to this, like not making it a loop at all. But I already got this far, not willing to go back to the drawing board yet.
while task.wait() do
if not HttpService.HttpEnabled then
break
end
if shared.MasterDiscordKey then
if table.maxn(shared.DiscordQueue) > 0 and not Cooldown then
Cooldown = true
if shared.DiscordQueue and shared.DiscordQueue[1] then
local Key = Alpha.MasterDiscordKey
local Success, Failed = pcall(function()
HttpService:PostAsync(Key, HttpService:JSONEncode(shared.DiscordQueue[1]))
end)
if not Success then
warn("[".. script.Name.. "]: System error - ".. tostring(Failed))
else
print("[".. script.Name.. "]: Sent Discord Webhook...")
end
table.remove(shared.DiscordQueue, 1)
end
task.wait(10) -- This breaks...
Cooldown = false
end
else
break
end
end