UserHasBadgeAsync Response Error

Server script inside the part:

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

I made the BadgeID 0000 on purpose
So, I don’t get any error when I touch the part, but when I touch the part repeatedly, it gives an error like this:
Screenshot_1
How to fix that?

  1. Try to add a debounce.
  2. Try to wrap the badge checker in a pcall.

You need to check if ‘player’ exists first before attempting to index its ‘UserId’ property.
if player then --before attempting to award the badge