Why won't BadgeService:AwardBadge() work

Ok, so, I’ve been making a game, and for some reason, One singular badge will not award.

I a currently waiting for a player to click a textbutton on a LocalScript, and then running a server event on a RemoteEvent.

Here are my scripts:

  1. Local:
function Roller()
	for _, Chance in pairs(Items) do
		Weight += (Chance * 10)
	end

	local ranNumber = math.random(1, Weight)

	Weight = 0 
	for Prize, Chance in pairs(Items) do
		Weight += (Chance * 10)

		if Weight >= ranNumber then
			if hideprint == false then
				print(Prize.." was won")
			end
			local Clone = script.Rolling:Clone()
			Clone.Parent = script.Parent
			Clone.Text = "Rolling..."
			wait(2)
			Clone.Text = "You got: "..tostring(Prize)
			wait(1)
			Clone:Destroy()
			
			WordsSF:WaitForChild(Prize).TextColor = BrickColor.new("Lime green")
			game.ReplicatedStorage.Badge:FireServer(6433767682) -- The RemoteEvent
		
			break
		end
	end
end

It’s a simple chance system, but when you roll for the first time, it is met to give a badge.

Next, there is a script in ServerScriptService:

game.ReplicatedStorage.Badge.OnServerEvent:Connect(function(Plr, Id)
	print("Badge")
	game:GetService("BadgeService"):AwardBadge(Plr.UserId, Id)
end)

I am certain that the remote event is working, seeing as in the output I get:

Badge

But nothing else there are no errors… and no badge.

2 Likes

You cannot award badges in Roblox studio I think. Moreover, you own the badge since you created it, so you won’t (read : CANT) be awarded the badge

1 Like

@MysteryX2076


– This shows I Don’t own it, if I did, then I would own all the other ones I made and they wouldn’t work either

Also, I know you can’t award in Studio, I am testing the game in normal Roblox.

2 Likes

These are the requirements I found on the docs, check if one of them is false

  • The player must be presently connected to the game.

  • The player must not already have the badge (note that a player may delete an awarded badge from their profile and be awarded the badge again).

  • The badge must be awarded from a server-side Script or aModuleScript eventually required by a Script, not from a LocalScript.

  • The badge must be awarded in a place that is part of the game associated with the badge.

  • The badge must be enabled; check this using the IsEnabledproperty of the badge fetched through BadgeService:GetBadgeInfoAsync().

2 Likes

Yes, I have already found and checked those.

1 Like

Hmm then I’m at a loss
Wrap that thing in a pcall to find out the error, because if you did everything right then idk

1 Like

kk

thirtycharacters30

1 Like

function Thing (Plr, Id)
	print("Badge")
	game:GetService("BadgeService"):AwardBadge(Plr.UserId, Id)
end


game.ReplicatedStorage.Badge.OnServerEvent:Connect(function(Plr, Id)
	pcall(Thing(Plr, Id))
end)
1 Like

Then the plr simply does not exist

1 Like

maybe try defining badge service before awarding the badge like this
local bs = game:GetService(“BadgeService”)
bs:AwardBadge(plr.UserId, Id)

1 Like

Have you checked if there are any typos in your scripts? Do the badge ID’s match? Is the badge properly set up in the game? Have you made another player/friend test if it works for them?
Also, here’s an example of how your Script should look like.
Script, ServerScriptService

local badgeService = game:GetService("BadgeService")
local badgeId = 6433767682 --Unsure whether this is the badge ID or not, probably best to check

game.ReplicatedStorage.Badge.OnServerEvent:Connect(function(player, badgeId)
    if badgeService:UserHasBadgeAsync(player.UserId, badgeId) then
        warn(player.Name .. " already has the badge.") --I added warnings and print statements so that if another problem arises, we can check through print statements, just to save time you know.
    else
        local success, err = pcall(function()
            badgeService:AwardBadge(player.UserId, badgeId)
        end)
        if success then
            print("Badge successfully awarded to " .. player.Name)
        else
            warn("Failed to award badge: " .. err)
        end
    end
end)
1 Like

@MysteryX2076 - I know, I’m just confused why the player would’t exist if they are calling the remote event

@yesssssssss90900 - This post is very unhelpful
I already know the problem, the player cannot be found, so what you said is useless.

Tried already

ThirtyCharacters30

Could u show the code where you fire the remote event?

._. I have already:

function Roller()
	for _, Chance in pairs(Items) do
		Weight += (Chance * 10)
	end

	local ranNumber = math.random(1, Weight)

	Weight = 0 
	for Prize, Chance in pairs(Items) do
		Weight += (Chance * 10)

		if Weight >= ranNumber then
			if hideprint == false then
				print(Prize.." was won")
			end
			local Clone = script.Rolling:Clone()
			Clone.Parent = script.Parent
			Clone.Text = "Rolling..."
			wait(2)
			Clone.Text = "You got: "..tostring(Prize)
			wait(1)
			Clone:Destroy()
			
			WordsSF:WaitForChild(Prize).TextColor = BrickColor.new("Lime green")
			game.ReplicatedStorage.Badge:FireServer(6433767682) -- The RemoteEvent
		
			break
		end
	end
end

Could u wrap it in an pcall like this?


local awardSuccess, result = pcall(function()
				return BadgeService:AwardBadge(player.UserId, badgeId)
			end)

Also print result

Infdfubeunehfuehfenfun3

Do u mind reading the other posts here

Y put the pcall up wrong, u need to actually get an error result.