How do I make a script where players can earn badges from having a certain amount of KO’s and Streaks?
1 Like
Listen for when the Streak and KO values change, then if it’s equal to a specific value - award them a badge.
If it’s not a value and instead an attribute or what not (rather pointless) - you could make a function in the script giving the KOs and Streaks to do the same as above, check if the value is equal to something and award the badge.
local BadgeService = game:GetService("BadgeService")
local killsToGet = 100 -- How many kills are required to obtain the Badge
local BadgeId = 000000000 -- Replace with your BadgeId
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local Kills = Instance.new("IntValue")
Kills.Name = "Kills"
Kills.Value = 0
Kills.Parent = leaderstats
Kills:GetPropertyChangedSignal("Value"):Connect(function()
if Kills.Value >= killsToGet then
local success, hasBadge = pcall(function()
return BadgeService:UserHasBadgeAsync(plr.UserId, BadgeId)
end)
if success and not hasBadge then
local awardSuccess = pcall(function()
BadgeService:AwardBadge(plr.UserId, BadgeId)
end)
end
end
end)
end)