Detect if a player has all badges in your game

Hey developers!
I am trying to figure out a way to detect if a player has all the badges in my game with a table, but all the tutorials that I have looked into haven’t helped all too much. If you know a way to get this to work, that would be amazing!

repeat wait(1) until game.Players.LocalPlayer.CharacterAppearanceLoaded

local function BadgeCheck()
	local badge = game:GetService("BadgeService")

	local badgetable = {
		FloodedHouse = 2127574368;
		Terry = 2127578391;
		AbsurdLoneliness = 2127596914;
		Contentment = 2127596982;
		Welcome = 2127597050;
		GoldenBear = 2127938411;
		Forlronness = 2128201703;
		CrownofInsanity = 2128833894;
		Shiny = 2130658850;
		Wendigo = 2132577623;
		Mysterious = 2140966601;
		StaticSultan = 2141170672;
		CreepyCrawler = 2141171086;
		TumultuousTerror = 2141171236;
		LurkingLoneliness = 2141171287;
		FalseFigure = 2141171327;
		EerieEntry = 2141171375;
		PerpetratingPupils = 2141178429;
		RadiantRemorse = 2141179609;
		InvigoratingIntrusion = 2141179659;
		SecretSurveillance = 2141179876;
		CreepyCode = 2141179924;
		DescendingDarkness = 2141314091;
		RadioResemblance = 2141356652;
		EventualEquity = 2141366314;
		DecayingDrop = 2142661585;
		ImaginaryInsermount = 2142661822;
		Normality = 2143448471;
		Vulnerability = 2143448550;
		Insanity = 2143448797;
		WorryingWatcher = 2145540716;
		Limbo = 2146140867;
	}

	for x, c in pairs (badgetable) do
		if badge:UserHasBadgeAsync(game.Players.LocalPlayer.UserId,#badgetable) == true then
			print("Works")

			game.ReplicatedStorage.HouseBuy:FireServer("TrophyBadge")
			script.Parent.Text = "Equip"
			script.Parent.Equip.Enabled = true
			script.Parent.Parent.Parent = script.Parent.Parent.Parent.Parent.Parent.Parent.Inventory.SkinsFrame.HouseSkins
		end
	end

end

if game.Players.LocalPlayer.houseskins.TrophyValue.Value == 1.12 then
	script.Parent.Parent.BorderSizePixel = 4
	script.Parent.Text = "Unequip"
	script.Parent.Equip.Enabled = true
	script.Parent.Parent.Parent = script.Parent.Parent.Parent.Parent.Parent.Parent.Inventory.SkinsFrame.HouseSkins

elseif game.Players.LocalPlayer.houseskins.TrophyValue.Value == 1.1 then
	script.Parent.Text = "Equip"
	script.Parent.Equip.Enabled = true
	script.Parent.Parent.Parent = script.Parent.Parent.Parent.Parent.Parent.Parent.Inventory.SkinsFrame.HouseSkins

else
	print("test")
	BadgeCheck()
end
script:Destroy()

Thank you for giving this post a read! Any help would be greatly appreciated! :heart:

you can iterate through the entire table of badges and check if they have the badge using UserHasBadgeAsync

local OwnedBadges = {} -- to check owned badges


for name, Id in badgetable do -- to iterate through the entire table
    local success, result = pcall(badge.UserHasBadgeAsync, badge, userId, Id) -- to check if the Player has the badge based on the value given
    -- pcall is just in case the code errors
    if success and result == true then -- if it was successful and they do own the badge
        table.insert(OwnedBadges, name) -- adds name to table to count towards the amount they own
    end
end

local percentage = math.floor((#OwnedBadges/#badgetable) * 100) -- calulates the percentage

print(percentage.."%") -- if its exactly 100%, that means they have all the badges

1 Like

it works! Thank you so much Cairo!

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