Badge Not Being Awarded

Problem: I keep having this error

It keeps saying something about UserID, and how player dosent exist.
I honestly have no idea what is going on.

local part= script.Parent
local Players = game:GetService("Players")
local badgeService = game:GetService("BadgeService")

local function GiveBadge(CharacterPart)
	local CharacterModel = CharacterPart.Parent
	local player = Players:GetPlayerFromCharacter(CharacterModel)
	if badgeService:UserHasBadgeAsync(player.UserId, 3475182492337699) == true then
		--Do Nothing
	else
		badgeService:AwardBadge(player.UserId, 3475182492337699)
	end
end

part.Touched:Connect(GiveBadge)

You aren’t checking if whats actually touching the part is a player or not.
Pretty simple fix:

local player = Players:GetPlayerFromCharacter(CharacterModel)

if not player then
   return
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.