Hi there!

I have a Badge Script that I found from an article on the roblox dev wiki and tried applying to a Script located in the ServerScriptService and it didn't work. Here's the code I used:

local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
 
local badgeID = 2124458670  
 
local function onPlayerAdded(player)
 
	local hasBadge = false
 
	-- Check if the player has the badge
	local success, message = pcall(function()
		hasBadge = 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: " .. tostring(message))
		return
	end
 
	if hasBadge == true then
		-- Assign this player a property/indicator that they own the badge
		--
	else
		BadgeService:AwardBadge(player, badgeID)
	end	
end
 
-- Connect "PlayerAdded" events to the "onPlayerAdded()" function
Players.PlayerAdded:Connect(onPlayerAdded)

Thank you!

4 comments

0

What error are you getting?

0

No errors, it just doesn't award the badge. The badge is active, and everything should work.

0

Do you already own the badge?

0

Yes. But I have tested it various times and wait various days and it hasn't worked