Badge Award Not Working

script.Parent.Touched:Connect(function(part)
	local part1 = part
	if part1.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(part1.Parent)
		local USERID = player.UserId
		game:GetService("BadgeService"):AwardBadge(USERID, *ID HERE*)
	end
end)

The error is “attempt to index nil with ‘userid’”

Please Help

LaregHotDogs13

local badgeservice = game:GetService("BadgeService")
local id = --Insert badge ID here

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)

This Error Still SHows Up

attempt to index nil with ‘UserId’

local function awardBadge(hit)
	if hit.Parent:FindFirstChildWhichIsA("Humanoid") then
		local plr = game.Players:FindFirstChild(hit.Parent.Name)
		game:GetService("BadgeService"):AwardBadge(plr.UserId, badgeId)
	end
end


script.Parent.Touched:Connect(awardBadge)

If you have NPCs in your game you might want to use a different method for determining if it’s a player but this should work fine. Might be beneficial to use a pcall for :AwardBadge as well.

Did you do this:

You should see your created badge here:

Then add the id of badge:

image

Use the numbers for the ID of badge

Theres still the same error

local badgeId = – my id is here

local function awardBadge(hit)
if hit.Parent:FindFirstChildWhichIsA(“Humanoid”) then
local plr = game.Players:FindFirstChild(hit.Parent.Name)
game:GetService(“BadgeService”):AwardBadge(plr.UserId, badgeId)
end
end

script.Parent.Touched:Connect(awardBadge)

Yep BTW its a group badge would that make a difference

And a group game

To confirm your player is touching the part, correct? Could you give more information regarding what type of script this is, as well as if this is the entire script and where it is located?

1 Like

Not that I know of, it works the same for groups as well

yep

i run over it then the error happens

In theory this should work. Not sure why it isn’t. For debugging purposes, would you adding print(plr.UserId) right below the local plr = line and letting me know what it outputs?

Also it might be worthwhile mentioning I don’t believe you’re able to award badges in Studio. You also must own the badge yourself (or in your case, the game must be a group game where the badge is owned).

1 Like

It Prints My UserId need characters

And for some reason it gave me the badge now