Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does this not award the badge?

Asked by 8 years ago

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

Log in to vote
1
Answered by
RafDev 109
8 years ago

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]

0
Still doesn't work :( Any ideas? jjwood1600 215 — 8y
0
Ah - it works if you rejoin the game once you have earned the required coins... but just realised why :D jjwood1600 215 — 8y
0
Oh sorry. Edited. RafDev 109 — 8y
0
Thanks! jjwood1600 215 — 8y
View all comments (4 more)
0
No problem :) RafDev 109 — 8y
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 jjwood1600 215 — 8y
0
Cant see why it doesn't work :/ Tried to fix it but not sure what's wrong! jjwood1600 215 — 8y
1
Try now RafDev 109 — 8y
Ad

Answer this question