Badges are broken in my game

image
The badge system has been working fine in my game and now all of a sudden it doenst work at all. I need the badge system to work for my game to be playable. Does anyone know why this is happening?

This is a script that awards the player a badge when they join
image
It was working fine before today and now its just broken.

1 Like

You should probably wrap the BadgeService calls in a pcall to handle errors. Other than that I’m not sure why that error would happen, as a fail-safe you could also try checking/awarding the badge like 10 seconds later if an error occurs again. Roblox has a code example on how to use BadgeService efficiently (when a player joins the game):

local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")

local badgeId = 00000000 -- Change this to your badge ID

local function onPlayerAdded(player)
	-- Check if the player has the badge
	local success, hasBadge = pcall(function()
		return BadgeService:UserHasBadgeAsync(player.UserId, badgeId)
	end)

	-- If there's an error, issue a warning and exit the function
	if not success then
		warn("Error while checking if player has badge!")
		return
	end

	if hasBadge then
		-- Handle player's badge ownership as needed
		print(player.Name, "has badge", badgeId)
	end
end

-- Connect "PlayerAdded" events to the "onPlayerAdded()" function
Players.PlayerAdded:Connect(onPlayerAdded)

If you are encountering this issue while testing in Roblox Studio then I see why. Studio servers are unable to handle badge awards, test your thing on a game server.

Maybe the game isn’t loaded yet, try to add the characteradded and wait() after the playeradded, and see if it resolves

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(character)
		wait(3)
		local owned = badgeservUserHasBadgeAsync(plr.UserId, 2148715202)
		if not owned then
			badgeserv:AwardBadge(plr.UserId, 2148715202)
		end
	end)
end)

Ok so just like how the badge service stopped working randomly it also fixed itself randomly. The game is working now thanks for responding guys.

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