and because of using touched hence requests occur all the time
local N = game:GetService("BadgeService")
local function _(a)
local R = false
local hum = a.Parent:FindFirstChild("Humanoid")
if hum then
local plr = Q:GetPlayerFromCharacter(a.Parent)
if plr then
wait(60)
R = true
if R == true then
if not N:UserHasBadgeAsync(_.UserId, j) then
N:AwardBadge(_.UserId, j)
end
end
R = false
end
end
end
award.Touched:Connect(_)
local N = game:GetService("BadgeService")
local debounce = false
local function _(a)
if debounce == false then
debounce = true
--Your function code here--
debounce = false
end
end
award.Touched:Connect(_)
I mean yeah it works without using wait() but the thing is that it too paused for a moment and then debounce is set to false again, but how?
if debounce == false then
debounce = true
if hum then
local plr = Q:GetPlayerFromCharacter(a.Parent)
if plr then
if not N:UserHasBadgeAsync(_.UserId, j) then -- something to do with this?
N:AwardBadge(_.UserId, j)
end
end
end
debounce = false -- it doesnt instantly set back to false though there aint a wait()
end
Simple, :UserHasBadgeAsync() takes some time to check if players owns the badge in question so this makes the code yield for a short while until it returns a result.
local debounce = os.time()
local DebounceTime = 6 -- seconds
local function _(a)
if (os.time() - debounce) >= DebounceTime then
debounce = os.time()
end
end
P.S. I would recommend using time() instead. It’s a silly nitpick of mine to give here but os.time is probably better used when you need to work with real dates and time for systems that can last more than a few sessions or a long time period. Mostly deriving my information from here: