How can to stop this message "we already gave out the badge"

I want to achieve is :

To stop this annoying message that spams my console and literally make a lag in my game.

*Script that gives badge

- Script

script.Parent.Touched:Connect(function(part)
	if part.Parent:FindFirstChild('Humanoid') then
		local player = game.Players:GetPlayerFromCharacter(part.Parent)
		game:GetService("BadgeService"):AwardBadge(player.UserId, 2124586648)
	end
end)

Issues :

We already gave out the badge..

1 Like

How about a Debounce Patterns | Roblox Creator Documentation.

1 Like

@Scottifly … Like that?

   local deb = false
    script.Parent.Touched:Connect(function(part)
    	if part.Parent:FindFirstChild('Humanoid') then
    		if deb == false then
    			local player = game.Players:GetPlayerFromCharacter(part.Parent)
    			wait()
    			game:GetService("BadgeService"):AwardBadge(player.UserId, 2124586648)
    			deb = true
    		end
    		end
    end)

Use a debounce or check if the user already owns the badge (but may cause some issues if touched is firing a lot).

Don’t use debounce for that and instead check if the player has already the badge.

1 Like

You can use a debounce and check if they have the badge.

2 Likes

But if the Humanoid touches the Scripted Part it’ll keep firing and checking if they have the Badge.
Wouldn’t it be better to have the debounce with the check as well?

You will need to make much more “advanced debounce” for it, because this will stop all players from “checking”. And btw the touch event will still fire no matter what.

What wrong here… i just make new one

local BadgeService = game:GetService("BadgeService")

local Players = game:GetService("Players")

local Player = game.Players.LocalPlayer

local OnCharacterAdded = true -- Choose

local badgeID = 2124586648

local OwnBadge = BadgeService:UserHasBadgeAsync(Player.UserId, badgeID)


script.Parent.Touched:Connect(function(part)
	if OwnBadge == true then
		
			
	if OwnBadge == false then
		if part.Parent:FindFirstChild('Humanoid') then
				
					local player = game.Players:GetPlayerFromCharacter(part.Parent)
					wait()
					game:GetService("BadgeService"):AwardBadge(player.UserId, 2124586648)
					
				end
		
		end
	
	end
	
end)

Error :

.Script:11: attempt to index nil with 'UserId'

1 Like
local BadgeService = game:GetService("BadgeService")
local Debounce = false

script.Parent.Touched:Connect(function(part)
	if Debounce then return end
	
	Debounce = true
	if part.Parent:FindFirstChildWhichIsA('Humanoid') then
		local player = game.Players:GetPlayerFromCharacter(part.Parent)
		--Check if they own the Badge
		if BadgeService:UserHasBadgeAsync(player.UserId, BadgeId) then
			return					
		end			

		--Else award them the badge
		BadgeService:AwardBadge(player.UserId, 2124586648)

	end

	wait(1)

	Debounce = false

end)

1 Like

Please don’t use debounces like that it will stop everybody from server because it is Script not Local Script.

1 Like

Yes i just realized that just now.

If you really want the debounce then do following:

local DebounceArray = {}

script.Parent.Touched:Connect(function(Hit) 
if Hit.Parent:FindFirstChildOfClass("Humanoid") then
if not table.find(DebounceArray,Hit.Parent.Name) then
table.insert(DebounceArray,Hit.Parent.Name) 
--do the check for badge
else
    return
       end
    end
end)

Not sure why everyone is saying you should use a debounce… that’s not a viable solution.

You are receiving this error because Roblox is attempting to award a badge to someone who already has it, the way to remedy this is to use an if statement in combination with
BadgeService:UserHasBadgeAsync.

1 Like

Perpect! Thats what im looking for. I dont have an idea that roblox have that form already!

I don’t get what you mean by that all you do is remove the debounce