Problem with badges

Hello, I have a problem with the emblems of my game, and it is that in the console all the time this is repeated:

image

Does anyone know what it could be? The script I use is this one:

local badgeservice = game:GetService("BadgeService")
local id = 2124628997

script.Parent.Touched:Connect(function(hit)

	if hit.Parent:FindFirstChild("Humanoid")then

		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		badgeservice:AwardBadge(plr.UserId,id)
	end
end)
1 Like

If you make a badge in individual game, the creator of that badge will awarded immediately after you create it, test either in your alt or friends

1 Like

You’re trying to give the player a badge on where by they already own the badge.

Firstly you will need to check if the user has the badge to avoid getting the warning you displayed.

This can be achieved by using UserHasBadgeAsync

So with the script you have all you need to do is check is the user has a badge.

local badgeservice = game:GetService("BadgeService")
local id = 2124628997

script.Parent.Touched:Connect(function(hit)

    if hit.Parent:FindFirstChild("Humanoid")then

        local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
        --Check if the player has the badge here
        local success, hasBadge = pcall(function()
            return badgeservice:UserHasBadgeAsync(plr.UserId, id)
        end)
        if(hasBadge) then
            --If the player has the badge, just return
            print(plr.Name.." already has this badge.")
            return
        else
            --If the player does not have the badge yet give them the badge
            badgeservice:AwardBadge(plr.UserId,id)
            print(plr.Name.." received the badge.")

        end
    end
end)

Edit: You’re also able to remove the badge from your profile and test the script.
I also added print statements for debugging purposes.

1 Like

Is that normal?

I updated the script for you. That was just a typo.

Ready, the console put this after it has the emblem:
image

I get a lot of them. Is this normal?

image

local debounce = false
local badgeservice = game:GetService("BadgeService")
local id = 2124628997
if not debounce then
debounce = true
script.Parent.Touched:Connect(function(hit)

	if hit.Parent:FindFirstChild("Humanoid")then

		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		badgeservice:AwardBadge(plr.UserId,id)
	end
end)
debounce = false
end

This appears.

image

Yeah, that is normal as you are using a touched event. If touch the part that triggers the function. You can get rid of the print statements as it works as intended.

Is there any way to prevent it from appearing? It is a bit annoying that it keeps repeating.

I told you that you can get rid of the print statements. Those are used for debugging purposes. And in your case the script works as intended not in need of the print statements/debugging.

local badgeservice = game:GetService("BadgeService")
local id = 2124660126

script.Parent.Touched:Connect(function(hit)

	if hit.Parent:FindFirstChild("Humanoid")then

		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		local success, hasBadge = pcall(function()
			return badgeservice:UserHasBadgeAsync(plr.UserId, id)
		end)
		else
			badgeservice:AwardBadge(plr.UserId,id)
			print(plr.Name.." received the badge.")

		end
	end
end)

Is this okay?

Sorry for not having read before that I should remove the printouts. I was distracted

That should be good, though you do not need the print statements.

1 Like
local badgeservice = game:GetService("BadgeService")
local id = 2124660126

script.Parent.Touched:Connect(function(hit)

	if hit.Parent:FindFirstChild("Humanoid")then

		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		local success, hasBadge = pcall(function()
			return badgeservice:UserHasBadgeAsync(plr.UserId, id)
		end)

Now?

The above methods are good, but here is something faster.

local badgeservice = game:GetService("BadgeService")
local id = 2124628997

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid")then
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		local Badges = plr:FindFirstChild("Badges") or Instance.new("Folder", plr)
		Badges.Name = "Badges"
		
		if not Badges:FindFirstChild(tostring(id)) then
			local success, hasBadge = pcall(function()
				return badgeservice:UserHasBadgeAsync(plr.UserId, id)
			end)
			if success and not hasBadge then		badgeservice:AwardBadge(plr.UserId,id)		end			
			Instance.new("StringValue", Badges).Name = tostring(id)
		end		
	end
end)

UserHasBadgeAsync will pause the script each time it checks, this method will only check once.

1 Like

I get this

image

Ah tu hablas español, mejor comuniquémonos así.

Bueno, como te decĂ­a, me sale esto cuando toco el emblema, y lo que yo quiero es que no salga nada Âżsabes que debo hacer? :frowning:

image