Custom badge awarding script not working because.. "can't convert nil to number"? What?

Hello,
I am making a custom badge award ui, because roblox’s badge award UI doesn’t support custom badge descriptions.
However, when trying to do this, I keep running into the same exact issue. “Value of nil can not be converted into number.”

Here’s the kicker: I’m passing a number, and the badge itself awards, but the rest of the script seems to not work.

I’ve tried everything, but I can’t find a solution to this issue at all. This is either a weird roblox lua bug, or something else…

MODULE SCRIPT:

local module = {}

local bs = game:GetService("BadgeService")

local bag =  script.badgeAwardedGui

function module.AwardBadge(userid, badgeid)
	bs:AwardBadge(userid, badgeid)
	
	if typeof(userid) ~= "number" then
		warn("userids gotta be a numero pal")
	end
	if typeof(badgeid) ~= "number" then
		warn("badge gotta be a numero pal")
	end
	
	local plr = game.Players:GetPlayerByUserId(userid)
	local ui = bag:Clone()
	
	if plr then
		ui.Parent = plr.PlayerGui
	else
		warn("No Player.")
		ui:Destroy()
	end

	
	local yay, nay = pcall(function()
		local badgeInfo = bs:GetBadgeInfoAsync(badgeid)

		ui.BadgeName.Value = badgeInfo.Name
		ui.BadgeDesc.Value = badgeInfo.Description
		ui.BadgeImageID.Value = badgeInfo.IconImageID
	end)
	if nay then
		warn(nay)
		ui.BadgeName.Value = tostring(badgeid)
		ui.BadgeDesc.Value = nay
		ui.BadgeImageID.Value = "rbxassetid://2592670412"
	end
	
end

return module

SERVER SCRIPT:

local bs = require(game.Workspace:WaitForChild("ModuleScript"))

task.wait(5)
for i,v in pairs(game.Players:GetPlayers()) do
	bs.AwardBadge(v.UserId,  2123456789)
end

Which line is this occurring on?

1 Like

You’re receiving this warning: “value of type nil cannot be converted to number”.

For the sake of simplicity, you can assume this type of warning is raised when you attempt to set anything but a number to an IntValue/NumberValue. In your case, you’ve attempted to set nil to the “Value” property. Through minor reasoning, you narrow down the problem to the properties of the resulting BadgeService:GetBadgeInfoAsync call:

Here, we can see that “IconImageID” is actually “IconImageId”. Make this correction in your script and it will work as intended

no line, it’s a warning sent by the pcall

Thank you so much for this. I would have never caught this. GPT was saying that the “badge id was too large for roblox to handle” :skull:

lowkey they should have this stuff listed in studio Aswell as the docs…

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