Unique Badge Giver

I’m making a game in which there is a fireplace a you put fire wood on the coal which activates it. It works but I’m trying to make it so that when you place the wood you get an achievement.

My issue is that I cannot seem to make it where you can actually get the badge, I have the fire in another script but this is the script that I have for the badge:

local badgeID = 2124692720
local badgeService = game:GetService("BadgeService")

function onFireEnabled(player)
	if script.Parent.Fire.Enabled == true then
	if not badgeService:UserHasBadge(player.UserId, badgeID) then
	badgeService:AwardBadge(player.UserId, badgeID)
		end
		end
	end```

I've tried many solutions like implementing the code into the fire activation code but that did not work. I've tried a lot of things that just didn't work, please help if possible.
2 Likes

What does fire the function onFireEnabled in this script?

You could try something like this:
function onFireEnabled(player)
if script.Parent.Fire.Enabled == true then
if not badgeService:UserHasBadge(player.UserId, badgeID) then
badgeService:AwardBadge(player.UserId, badgeID)
end
end
end
onFireEnabled()

Try this:

local BadgeService = game:GetService("BadgeService")


local function AwardBadge(Player, BadgeId)
	
	local success, badgeInfo = pcall(function() return BadgeService:GetBadgeInfoAsync(BadgeId) end)
	if success then
		local success, hasBadge = pcall(function() return BadgeService:UserHasBadgeAsync(Player.UserId, BadgeId) end)
		if not success then warn("[ERROR]: UserHasBadgeAsync") return false end	
		if not hasBadge  then 
			local awarded, errorMessage = pcall(function() BadgeService:AwardBadge(Player.UserId, BadgeId) end)
			if not awarded then warn("[ERROR]: while awarding badge:", errorMessage) return false  end
		end	
	else warn("[ERROR]: fetching badge info!") return false end
	
end


function onFireEnabled(player)
	
	local badgeID = 2124692720
	if script.Parent.Fire.Enabled == true then AwardBadge(player, badgeID) end
	
end

It should print out any errors if there is a problem awarding the badge to give you an easier time debugging.

2 Likes

Doesn’t seem to work, nor are there any errors…

Then the problem has to lie in one of the above.
Either the function isn’t being called or the Fire.Enabled is not true when it’s being checked.
Replace the function with the following code and check the output:

function onFireEnabled(player)
	print("onFireEnabled Called")
	local badgeID = 2124692720
	if script.Parent.Fire.Enabled == true then AwardBadge(player, badgeID) else print("Fire.Enabled=false") end
	
end

You forgot to call the function, maybe that is why it’s not working.
If you called it and it still doesn’t work, Message me and I’ll help.

-David