Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to count badges of a player?

It has to count the badges of the local player This belongs inside gui in a local script Inside a textlabel within too a NumberValue named "Ei" But this seems not to work. Whats wrong?

local player = game.Players.LocalPlayer
local BadgeService = game:GetService("BadgeService")
local badges  = {229929415, 229929797}
function countBadges()
    local Egg = script.Parent.Ei -- Name of NumberValue
	local Eggs = 0
    for _, badge in next, badges do
        if BadgeService:UserHasBadge(player.UserId, badge) then
            if Eggs == Eggs + 1 then
			Egg = Egg.Value + 1
			else
			print ("fail")
			end
        end
    end
    return Eggs
end


while true do
	countBadges()
	script.Parent.Text = script.Parent.Ei.Value.."".."/2"
	wait(0.5)
end

thank you

1 answer

Line 10 Egg = Egg.Value + 1 should be Egg.Value = Egg.Value + 1 Also, Eggs will never be equal to Eggs + 1, with the exception of +/- infinity and rounding errors.

This discussion is preserved as it was. New answers, comments, and votes are closed.