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

Why does this not award the badge?

Hi guys! Any ideas why this doesn't award the badge? There are no errors. Any help would be appreciated ;) Thanks!

local LeaderboardString = "Coins"
local RequiredValue = 1000
local BadgeID = 217045131

game.Players.PlayerAdded:connect(function(Player)
    local LeaderboardInstance = Player:WaitForChild(LeaderboardString)
wait(1)
    if LeaderboardInstance.Value >= RequiredValue then
        game:GetService("BadgeService"):AwardBadge(Player.userId, BadgeID)
    end
end)


1 answer

✓ Accepted answer

I'm not sure of how you're organizing your game, but I believe you can't look for "Coins" as a direct child of Player, if you're using a leaderstat.

Thus, this should work:

local LeaderboardString = "Coins"
local RequiredValue = 1000
local BadgeID = 217045131

game.Players.PlayerAdded:connect(function(Player)
    local LeaderboardInstance = Player:WaitForChild('leaderstats'):WaitForChild(LeaderboardString) -- Wait for leaderstats first, then for the LeaderboardString
LeaderboardInstance.Changed:connect(function()
wait(1)
    if LeaderboardInstance.Value >= RequiredValue then
        game:GetService("BadgeService"):AwardBadge(Player.userId, BadgeID)
    end
end)
end)



Hope it helps! :) Comment if it doesn't work, and you're using a different scheme.

[EDIT: Added Changed event]

8 comments

0

Still doesn't work :( Any ideas?

0

Ah - it works if you rejoin the game once you have earned the required coins... but just realised why :D

0

Oh sorry. Edited.

0

Thanks!

0

No problem :)

0

Changed event still doesn't work :/ Just tested it... sorry, but do you mind trying to fix it again ?:/ I'm rubbish at badge awarding lol :D

0

Cant see why it doesn't work :/ Tried to fix it but not sure what's wrong!

1

Try now

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