Making a gui show how many badges were awarded

Hi, I’m trying to make a gui that appears when a player touches a part and it starts awarding badges, while showing how many badges were awarded. So far it makes the gui appear, and doesn’t change the text. I’m going to make it award the badges last, as it is the most simple part. Here is the script I made:

local badges = {000,001,002}
local a = script.Parent.badgenumber
local badgeService = game:GetService("BadgeService")

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        player.PlayerGui.ScreenGui.b.Visible = true
        player.PlayerGui.ScreenGui.Frame.Visible = true
        for i, badge in pairs(badges) do
            wait(1)
            a.Value = a.Value + 1
            player.PlayerGui.ScreenGui.Frame.TextLabel.Text = (a).."/3"
        end
    end
end)

If you see anything wrong please let me know.

1 Like

Change to:

if badgeService:UserOwnsBadgeAsync(player.UserId,badge) then
    a.Value += 1
    player.PlayerGui.ScreenGui.Frame.TextLabel.Text = (a.Value).."/3"
end

Thanks, I changed it to:

a.Value += 1

player.PlayerGui.ScreenGui.Frame.TextLabel.Text = (a.Value).."/3"

It goes over 3 sometimes, how do I prevent that?

I’m not sure why, but you can also approach it like this:

for i, badge in ipairs(badges) do
    if badgeService:UserOwnsBadgeAsync(player.UserId,badge) then
        a.Value += 1
    end
end
player.PlayerGui.ScreenGui.Frame.TextLabel.Text = math.clamp(a.Value,0,#badges).."/"..(#badges)
1 Like