What do you want to achieve? I want a badge counter that refreshes every second so you don’t have to rejoin to see the badges you own
What is the issue? the current script I have works but it doesn’t refresh so players would have to rejoin
What solutions have you tried so far? I’ve private messaged to get it solved and made many dev forums but there are always bugs
local badgeIds = {2124871551, 2124871927, 2124874652, 2124875134, 2124875135, 2124875283, 2124883537, 2124883540, 2124883811, 2124883814, 2124883850, 2124883955, 2124883958, 2124885305, 2124902920, 2124902921, 2124902922, 2124903285, 2124903302, 2124903961, 2124903963, 2124903965, 2124904543, 2124904556, 2124906387, 2124907055, 2124907283, 2124907311}
local players = game:GetService("Players")
local badges = game:GetService("BadgeService")
local function onPlayerAdded(player)
local ls = Instance.new("Folder")
ls.Parent = player
ls.Name = "leaderstats"
local badgeCount = Instance.new("IntValue")
badgeCount.Parent = ls
badgeCount.Name = "Exorics"
for _, badgeId in ipairs(badgeIds) do
task.wait(0.35)
local succ, res = pcall(function()
return badges:UserHasBadgeAsync(player.UserId, badgeId)
end)
if succ then
if res then
badgeCount.Value += 1
end
else
warn(res)
end
end
end
players.PlayerAdded:Connect(onPlayerAdded)
How about in the Function that adds a badge you just add 1 to the Counter so it updates every time? Or put that in a Character added function so that even when they die it updates again cause the player-added function only runs once.
local badgeIds = {2124871551, 2124871927, 2124874652, 2124875134, 2124875135, 2124875283, 2124883537, 2124883540, 2124883811, 2124883814, 2124883850, 2124883955, 2124883958, 2124885305, 2124902920, 2124902921, 2124902922, 2124903285, 2124903302, 2124903961, 2124903963, 2124903965, 2124904543, 2124904556, 2124906387, 2124907055, 2124907283, 2124907311}
local players = game:GetService("Players")
local badges = game:GetService("BadgeService")
local function CharacterAdded (Character)
print(Character)
local player = game.Players:GetPlayerFromCharacter(Character)
local BadgeAmount = nil
BadgeAmount = player:WaitForChild("leaderstats"):WaitForChild("Exorics")
task.defer(function()
for _, badgeId in ipairs(badgeIds) do
local HasBadge = badges:UserHasBadgeAsync(player.UserId, badgeId)
if HasBadge then
BadgeAmount.Value += 1
else
warn(player.Name,"Does not have Badge ID: ",badgeId)
end
end
end)
end
local function onPlayerAdded(player)
local badgeCount = nil
local ls = nil
ls = Instance.new("Folder")
ls.Parent = player
ls.Name = "leaderstats"
badgeCount = Instance.new("IntValue")
badgeCount.Parent = ls
badgeCount.Name = "Exorics"
player.CharacterAdded:Connect(CharacterAdded)
end
players.PlayerAdded:Connect(onPlayerAdded)