Hello, I want to give people badges when it reaches a certain stage. But the problem is that I made the badges way too late and people already have reached a higher stage but won’t get the badges they were supposed to get when they were at a lower stage.
So what I want is a system where it can give people badges when it reaches a certain badge and gives a badge if they already reached a certain stage before.
badgecheck = [
25 = "badgerewardid",
]
game.Players.PlayerAdded:Connect(function(P)
for i,v in pairs(badgecheck) do
if P.Stage.Value >= i then
badgeservice award(v)
end
end)
while wait(1) do
for i,v in pairs(game.Players:GetChildren()) do
if v.leaderstats.Stage.Value >= 6 then
game:GetService("BadgeService"):AwardBadge(v.UserId,2125002441)
end
end
end
My friend made this for me, put a normal script in ServerScriptService and change 6 to any stage you want to award the badge and change 2125002441 to the badge ID you want to use.
That works but is inefficient and could also error if for example the BadgeService is unavailable.
local players = game:GetService("Players")
local badges = game:GetService("BadgeService")
local badgeId = 0 --Change to ID of badge.
local stageForBadge = 0 --Change to stage required for badge.
players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local stage = Instance.new("IntValue")
stage.Name = "Stage"
stage.Value = 0 --Starting stage.
stage.Changed:Connect(function(stageNumber)
if stageNumber >= stageForBadge then
local success, result = pcall(function()
return badges:UserHasBadgeAsync(player.UserId, badgeId)
end)
if success then
if not result then --Doesn't have badge.
local success2, result2 = pcall(function()
return badges:AwardBadge(player.UserId, badgeId)
end)
if success2 then
if result2 then
print("Badge successfully awarded to "..player.Name..".")
end
else
warn(result2)
end
end
else
warn(result)
end
end
end)
end)