Badge percentage script not changing text

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()

1 Like

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.

Theres an error that I dont know how to fix

Yeah it’s not GetUserAsync it’s UserHasBadgeAsync

5 Likes

If this is solved now, please mark my response a Solution.

1 Like

im not marking your sulution /// // /

Well does his code work for you?

2 Likes

are bros just liking their own comments :skull:

Yk you can’t do that right? You must be new explaining a lot

are you that arrogant?

thats sad, its one button click, he helped you.

you literally came back to the thread to defend you not marking it

Well if you don’t do it one of the roblox staff will mark it and close the topic. So I suggest we get this over with instead of extra drama :+1:

then you must be not explaining it too by saying im not explaining new whatever

womp womp i dont like the roblox staff anyways make their work harder hahhahahaha

helped me of what lol lol lol lol lol :skull: it didnt even work :skull::skull::skull::skull::skull:

Why didn’t you say so lil buddy? :skull:. Put the id’s of all badges in your game like this

local GameBadges = {
    — Add your badge id’s here. The ID is the SECOND set of numbers in the link to the badge
}

Then just do this in your update function instead

local percentage = (#(BadgeService:GetUserBadgesAsync(LocalPlayer.UserId,GameBadges)/#GameBadges)*100

how about no. ha ha ha ha har har

Ok man I guess your issue remains unresolved. Keep trying :wink:

its literally solved lil bro lil bro

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

i literally already put solved in different post -_-