How do you make a badge award depending on leaderstats data?

How do I make a script that awards you a badge if you gain for instance “5 kills” in the leaderstats?

1 Like

Pretty easy, check if kills value is equals and greater than 5.
Then award the player badge using BadgeService:AwardBadge()

Example code:

local leaderstats = player.leaderstats
local kills = leaderstats.Kills
local badgeService = game:GetService("BadgeService")

local badgeId = 0 -- Badge id here

if kills.Value >= 5 then -- If player's kills equals or greater than 5 then
   badgeService:AwardBadge(player.UserId, badgeId) -- Awards the player the badge for having 5 kills or above.
end
4 Likes

For some reason it gives me this error, how can I fix it?

Screenshot_4

Put this in a PlayerAdded event

game:GetService("Players").PlayerAdded:Connect(function(player)
-- put badge code here
end)
2 Likes