Awarding badge problem

So I want to make, if a player touch 3 button, they will get the badge. This is my script:

local badgeservice = game:GetService("BadgeService")
local id = 000
local debounce = true

script.Parent.ClickDetector.MouseClick:Connect(function(hit)
	debounce = false
	game.ReplicatedStorage.Counter.Value = game.ReplicatedStorage.Counter.Value + 1
	if game.ReplicatedStorage.Counter.Value == 3 then
		if hit.Parent:FindFirstChild ("Humanoid") then
			local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
			badgeservice:AwardBadge (plr.UserId, id)

		end
	end
	script.Parent:Destroy()
end)

Thanks, I hope someone know the problem!

Note: Only the last player that touch the button will get the badge

MouseClick gets the player who clicks the ClickDetector, not whatever hit it. I believe you’re confusing this with Touched. Try the following and let me know if it works out for you.

local BS = game:GetService("BadgeService")
local id = 000


script.Parent.ClickDetector.MouseClick:Connect(function(plr)
	game.ReplicatedStorage.Counter.Value = game.ReplicatedStorage.Counter.Value + 1
	if game.ReplicatedStorage.Counter.Value == 3 then
		BS:AwardBadge(plr.UserId, id)
	end
end)
1 Like

Its working perfectly, thank you so much!

1 Like

https://developer.roblox.com/en-us/api-reference/function/BadgeService/UserHasBadgeAsync

Might be worth checking this beforehand, so you don’t attempt to award the badge to a user that has already earned the badge.