Hello. I’m making a system where I award a player whenever they reach a milestone of a value. Issue is that it only awards the player for the first badge and the not the rest. How can I go about fixing this?
local badgeService = game:GetService("BadgeService")
local EachMileStone = {
[1] = 2149272327,
[100] = 2149272333,
[1000] = 2149272344,
[10000] = 2149272355,
[100000] = 2149272400,
}
local DoTheyHaveThisBadgeAlready = {}
game.Players.PlayerAdded:Connect(function(player)
repeat task.wait() until player:FindFirstChild("leaderstats") ~= nil
player.leaderstats.Bricks.Changed:Connect(function()
for i, v in EachMileStone do
if player.leaderstats.Bricks.Value >= i and table.find(DoTheyHaveThisBadgeAlready, v) == nil then
if not badgeService:UserHasBadgeAsync(player.UserId, v) then
print(v)
badgeService:AwardBadge(player.UserId, v)
end
table.insert(DoTheyHaveThisBadgeAlready, v)
elseif player.leaderstats.Bricks.Value < i then
return
end
end
end)
end)
It only outputs the first badge assetId and nothing else.
Any and all help is very much appreciated.
local badgeService = game:GetService("BadgeService")
local EachMileStone = {
[1] = 2149272327,
[100] = 2149272333,
[1000] = 2149272344,
[10000] = 2149272355,
[100000] = 2149272400,
}
local DoTheyHaveThisBadgeAlready = {}
game.Players.PlayerAdded:Connect(function(player)
repeat task.wait() until player:FindFirstChild("leaderstats") ~= nil
player.leaderstats.Bricks.Changed:Connect(function()
for i, v in pairs(EachMileStone) do
if player.leaderstats.Bricks.Value >= i and table.find(DoTheyHaveThisBadgeAlready, v) == nil then
if not badgeService:UserHasBadgeAsync(player.UserId, v) then
print(v)
badgeService:AwardBadge(player.UserId, v)
end
table.insert(DoTheyHaveThisBadgeAlready, v)
elseif player.leaderstats.Bricks.Value < i then
return
end
end
end)
end)
I had to keep player.UserId in AwardBadge since it’d throw up a “can’t cast instance to int64” error or something like that. Could it be because I’m using a difference place to test it than the place where the badges are?
I wrote something up for you, during initial testing before I added the leaderstats stuff this was printing all badge IDs, I probably messed something up but try this.
local badgeService = game:GetService("BadgeService")
local PlayerService = game:GetService("Players")
local EachMileStone = {
[2149272327] = 1,
[2149272333] = 100,
[2149272344] = 1000,
[2149272355] = 10000,
[2149272400] = 100000,
}
PlayerService.PlayerAdded:Connect(function(Player)
repeat task.wait(0.5) until Player:FindFirstChild("leaderstats") ~= nil;
Player.leaderstats.Bricks.Changed:Connect(function()
for BadgeIds, Values in pairs(EachMileStone) do
if Player.leaderstats.Bricks.Value >= Values then
if not badgeService:UserHasBadgeAsync(Player.UserId, BadgeIds) then
print(BadgeIds)
badgeService:AwardBadge(Player.UserId, BadgeIds)
end
end
end
end)
end)