Badge doesn't get awarded on part touched

My script is not working. It is supposed to award a badge to the player who touched a specific part (the script’s parent). CanTouch of the part is checked. And other parts with the same script gave me badges perfectly fine, in fact this part is a duplicate of the other parts. I do not have the badge in my Roblox inventory and I have tried this script in public servers but it still does not work.

My script:
local BadgeService = game:GetService("BadgeService")
local id = 000 -- badge id

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		if not BadgeService:UserHasBadgeAsync(plr.UserId, id) then
			BadgeService:AwardBadge(plr.UserId, id)
		end
	end
end)
The part and script:

image

I got badges from other parts with the exact script, just with different badge id, but in this part, it doesn’t work.

1 Like

The script works you probably have the wrong id or something like that

uhhm the script is correct but the id is 000 that means there are no badges to be awarded.

local BadgeService = game:GetService("BadgeService")
local PlayerService = game:GetService("Players")
local id = 000000 -- badge id


script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local plr = PlayerService:GetPlayerFromCharacter(hit.Parent)
		local success,result = pcall(function()
			return BadgeService:UserHasBadgeAsync(plr.UserId,id)
		end)
		if success then
			if result then -- if he has the badge
				warn("already owns")
			else
				--award him
			end
		end
	end
end)
2 Likes

You’re probably testing it out in Studio, you can only get badges in-game. Try publishing your game and testing it out that way.

1 Like

I rebuilt the part with the exact script and children now it works. It’s the exact copy but it works now.