Why won't BadgeService:AwardBadge() work


I got this

This ain’t how you wrap an pcall

:-1:

ThirtyCharacters30

Try using this


local function awardBadge(player, badgeId)
	-- Fetch badge information
	local success, badgeInfo = pcall(function()
		return BadgeService:GetBadgeInfoAsync(badgeId)
	end)

	if success then
		-- Confirm that badge can be awarded
		if badgeInfo.IsEnabled then
			-- Award badge
			local awardSuccess, result = pcall(function()
				return BadgeService:AwardBadge(player.UserId, badgeId)
			end)

			if not awardSuccess then
				-- the AwardBadge function threw an error
				warn("Error while awarding badge:", result)
			elseif not result then
				-- the AwardBadge function did not award a badge
				warn("Failed to award badge.")
			end
		end
	else
		warn("Error while fetching badge info: " .. badgeInfo)
	end
end

I still get no error or badge

This text will be blurred

Is there any prints? Like the output

nope

This text will be blurred

Uh are you sure you don’t have the badge?

I am certain - ur script would print that I had it otherwise

all my other badges are working tho

If you actually read my script, my script only prints when there is an error

it would still say error tho

This text will be blurred

I am certain the only thing going wrong is the player cannot be found.

That means there was no code error. It is probably your badge settings. Would u mind linking ur game? (If it’s public)

kk:

ur ment 2 get the badge when u roll

Did you actually call the function?
Let’s see ur code with my function



--__Config______________

local Items = {
	["~✨~"] = 09,
	["~πŸ”₯~"] = 20,
	["~❀️~"] = 35,
	["~⭐~"] = 12,
	["~🀩~"] = 10,
	["~🎡~"] = 10,
	["~πŸ˜€~"] = 40,

}

local hideprint = true



--___Player__________________________
local Player = game.Players.LocalPlayer
local Character = Player.Character
--___________________________________

--___Rolling_________
local Weight = 0
--___________________

--________Instances_______________

--_______DataStore____________

--					*_______W.I.P___________*

--                     * I hate Datastore*
--_____________

--________Rolling__________
local Roll = script.Parent.Roll
local Auto = script.Parent.Auto
--_________________________

--_______Words____________________
local WordsB = script.Parent.WordsB
local WordsF = script.Parent.WordsF
local WordsSF = WordsF.ScrollingFrame
local Wordst = WordsSF.Template
--________________________________

--________Settings_________________
local SettingsB = script.Parent.SettingsB
local SettingsF = script.Parent.SettingsF
--_________________________________







--____________Functions____________________________
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)
		
			break
		end
	end
end


--________________________________






--______Loaders_____________
for i, v in pairs(Items) do
	
	local Item = Wordst:Clone()
	Item.Parent = WordsSF
	Item.Name = i
	Item.Text = i.." - "..v.."%"
	
	Item.Visible = true
	
end
--___________________________





--__________Interations_______________________________________

Roll.MouseButton1Click:Connect(function()
	Auto.State.Value = false
	Auto.BackgroundColor = BrickColor.new("Bright red")
	Auto.Text = "Auto Roll: Off"
	
	Roll.Visible = false
	
	Roller()
	
	Roll.Visible = true
end)

Auto.MouseButton1Click:Connect(function()
	
	if game.Players.LocalPlayer:IsInGroup(34803435) then
		if Auto.State.Value == false then
			Auto.State.Value = true

			Auto.BackgroundColor = BrickColor.new("Slime green")
			Auto.Text = "Auto Roll: On"

			while true do
				if Auto.State.Value == true then
					Roller()
					wait(1)
				else
					break
				end
			end

		else
			Auto.State.Value = false
			Auto.BackgroundColor = BrickColor.new("Bright red")
			Auto.Text = "Auto Roll: Off"
		end
	else
		Auto.Text = "You must join the group for auto roll"
	end
end)

WordsB.MouseButton1Click:Connect(function()
	WordsF.Visible = not WordsF.Visible
end)

SettingsB.MouseButton1Click:Connect(function()
	SettingsF.Visible = not SettingsF.Visible
end)
1 Like

everything here is working fine, seeing as at the start I made it print β€œbadge” when it ran the remote event

What about the server code?

This text will be blurred