Global Leaderboard to Award Place Badges on Condition

What do I want to achieve - Use global leaderboard to award place badges to 1, 2, 3 place

Whats the issue - 1-Gold works ok when earned in isolation.
2- Silver. When earned is giving silver and gold badges,
3 - Bronze has been removed to simplify the code for the time being.
what solutions have I tried - Changed code many times looked for answers on dev hub.

Hello I am trying to achieve a global leaderboard that awards badges for 1,2,3 place.

The leaderboard is working and displaying the lowest time. The gold badge 1 works well when
earned by top player (lowest time)

However when you earn the silver badge 2 you are given the gold badge aswell.

I have tried to ‘get’ the correct player. The badges are awarded by stepping on a block
‘claimBadgeGold’ as thats the only way I can trigger the function Badgeservice.

There is most probably a better and working solution to this,.

the variable rankInLB is not an int value so I cant use .changedProperty on it

I will Include the section of code I am having problems with

				local BadgeService = game:GetService("BadgeService")
				local badgeIdGold = 2124616534
				local badgeIdSilver = 2124617843
				local badgeIdBronze = 2124618170
				local claimBadgeGold = game.Workspace.ClaimBadgeGold

				
				
				claimBadgeGold.Touched:Connect(function(hit)
					
					local plr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
						print("Gold Nearly Awarded")
											
					if plr and hit.Parent and rankInLB == 1 then -- plr works
							if not BadgeService:UserHasBadgeAsync(plr.UserId, badgeIdGold) then
								BadgeService:AwardBadge (plr.UserId, badgeIdGold)
								print("Gold Badge Claimed")
								print(plr.UserId, badgeIdGold)
							end
					end	
					
					if plr and hit.Parent and rankInLB == 2 then -- plr works
						if not BadgeService:UserHasBadgeAsync(plr.UserId, badgeIdSilver) then
							BadgeService:AwardBadge (plr.UserId, badgeIdSilver)
							print("Silver Badge Claimed")
							print(plr.UserId, badgeIdSilver)
						end
					end	


				end)

Any help or advice will be appreciated thanks

I have just re-tested this - update.

when you earn the gold badge you are given the silver as well. Great for collecting badges but not too
good for my project.

I suggest using
elseif instead of if, so only 1 badge will be given no matter what.

This is still awarding both badges for getting silver 2nd place

				claimBadgeGold.Touched:Connect(function(hit)
					
					local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
					
					
					if plr and rankInLB == 1 then
						if not BadgeService:UserHasBadgeAsync(plr.UserId, badgeIdGold) then
							BadgeService:AwardBadge (plr.UserId, badgeIdGold)
							end
					elseif plr and rankInLB == 2 then
							if not BadgeService:UserHasBadgeAsync(plr.UserId, badgeIdSilver) then
								BadgeService:AwardBadge (plr.UserId, badgeIdSilver)
							end
						
						
					end
				end)
					

I have been testing and working on this for many hours and am really stuck
this code awards the badge without even having a time or rankInLB

claimBadgeGold.Touched:Connect(function(hit)
					
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		print(hit.Parent)
					
					
	if plr and rankInLB == 1 then -- plr works
		if not BadgeService:UserHasBadgeAsync(plr.UserId, badgeIdGold) then
		BadgeService:AwardBadge (plr.UserId, badgeIdGold)							
		end
	end
end)

any help would be appreciated, thanks