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