How do i stop error spam from badge touch?

I tried debounce but that just waits until it starts spamming error messages once again


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(_)

any help?

You can add a debounce system like this:

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(_)
1 Like

so how does it even ‘wait’ for the badge until it switches debounce to false? because i dont think i see a wait()

The wait() is in your code, you just copy paste your code inside the function to the part where it’s written “–Your function code here–”.

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.

1 Like

You can do that type of debounce, or this too;

local debounce = os.time()
local DebounceTime = 6 -- seconds
local function _(a)
    if (os.time() - debounce) >= DebounceTime then
debounce = os.time()
    end
end
1 Like

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:

2 Likes