Roblox how to check if player awarded a badge

I tried to make custom badge gui. I need to check when badge is awarded.

Please help me, thanks!

1 Like

BadgeService.OnBadgeAward

Or

BadgeService.BadgeAwarded

I havent tested them, but I think they only can be used by core scripts.

1 Like

To check if a player has a badge you would do:

local badgeid = 0

game.Players.PlayerAdded:Connect(function(player)
 if game.BadgeService:UserHasBadge(player.UserId, badgeid) then
-- code
end
end)
2 Likes

I’ll try that out, thanks.
(char limit)

I don’t actually get the question.
You want to check if player get awarded a badge or player owns a badge?

Make sure to take a look at
https://developer.roblox.com/en-us/api-reference/class/BadgeService

On player awarded a badge.
(char limit)

What’s your use case?

Since you can’t access any of the implemented ones, I’m thinking you can make a bindable event and fire it whenever you award a badge, or create a BadgeService wrapper with a module script.

ex.

local badgeService = game:GetService('BadgeService')
local replicatedStorage = game:GetService('ReplicatedStorage')
local onBadgeAwarded = replicatedStorage:WaitForChild('OnBadgeAwarded') -- this should be a bindable event
-- ...in a function somewhere
local success, result = pcall(badgeService.AwardBadge, badgeService, player.UserId, badgeId)
onBadgeAwarded:Fire(success, player.UserId, badgeId)

Then in another script, make a listener for the onBadgeAwarded event:

local replicatedStorage = game:GetService('ReplicatedStorage')
local onBadgeAwarded = replicatedStorage:WaitForChild('OnBadgeAwarded')

onBadgeAwarded.Event:Connect(function(success, player.UserId, badgeId)
    print(success, player.UserId, badgeId)
end)
1 Like

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