Im trying to make a script that changes a text of the percentage of how much badges the player has gotten. For example: if the player has all the badges the text would change to 100% if the player has half of the badges it would be 50% and if the player has no badges it would be 0%
The script I made does not work I need help of this script to work
local Players = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")
local LocalPlayer = Players.LocalPlayer
local character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local function updateBadgePercentage()
local user = BadgeService:GetUserAsync(LocalPlayer.UserId)
local totalBadges = #user.Badges
local earnedBadges = 0
for i = 1, totalBadges do
if user.Badges[i].IsEarned then
earnedBadges = earnedBadges + 1
end
end
local percentage = 0
if totalBadges > 0 then
percentage = (earnedBadges / totalBadges) * 100
end
local textLabel = script.Parent
textLabel.Text = string.format("%d%%", percentage)
end
updateBadgePercentage()
local badgeIds = {
123456,
234567,
345678
}
for _, badgeId in ipairs(badgeIds) do
local success, hasBadge = pcall(function()
return BadgeService:UserHasBadgeAsync(LocalPlayer.UserId, badgeId)
end)
if success and hasBadge then
earnedBadges = earnedBadges + 1
end
end
I’m pretty sure you can get the player badges by the BadgeService. Try using a list of badges you want to check if the player has them.
Then you should place your soltion here and mark it so the topic would close. Point of dev forum is for everyone to learn together. If you don’t want to share mark your own post as solution