I have a Wins value for each player thats is stored in leaderstats and gets saved in a datastore.
Basically, when the players Wins value is updated, a local script fires a remote event. The Badge rewarder script, when the event is fired, gets the player name so that it can verify that the player actually has that many wins, and to make sure that even if a hacker changes stuff, they won’t get the badge.
Everything is working perfectly, except the fact that the badge is not getting rewarded.
I took a look at the dev documents that Roblox made about badge rewarding, and it doesn’t seem to work in my script…
local BadgeService = game:GetService("BadgeService") local ReplicatedStorage = game:GetService("ReplicatedStorage") local AwardBadgeRE = ReplicatedStorage:WaitForChild("AwardBadge") local function awardBadge(player, badgeId) -- Fetch badge information local success, badgeInfo = pcall(function() return BadgeService:GetBadgeInfoAsync(badgeId) end) if success then -- Confirm that badge can be awarded if badgeInfo.IsEnabled then -- Award badge local awarded, errorMessage = pcall(function() BadgeService:AwardBadge(player.UserId, badgeId) print("Badge awarded to player.") end) if not awarded then warn("Error while awarding badge:", errorMessage) end end else warn("Error while fetching badge info!") end end function VerifyReward(player) local leaderstats = player:FindFirstChild("leaderstats") local wins = leaderstats:FindFirstChild("Wins") if wins.Value == 50 then -- 50 BADGE print("player can get 50 wins badge.") awardBadge(player, 2124893711) elseif wins.Value == 100 then -- 100 BADGE print("player can get 100 wins badge.") awardBadge(player, 2124893712) elseif wins.Value == 500 then -- 500 BADGE print("player can get 500 wins badge.") awardBadge(player, 2124893713) else warn("Player not eligible for a badge yet.") end end AwardBadgeRE.OnServerEvent:Connect(VerifyReward)
Why is this not working?
the line *print(“Badge awarded to player.”) even prints, but the player does not get the badge…
what am I doing wrong?