How to make badge counter refresh every second?

  1. 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

  2. What is the issue? the current script I have works but it doesn’t refresh so players would have to rejoin

  3. 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)
1 Like

Did you try to make when the game award a badge to a player add 1 to his Exorics?

Have you tried a Value Changed or a Loop Function??

yea but that just makes it add the value multiple times instead of just refreshing and checking if the player won any new badges

That’s what the script does tho

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.

How would that script look like?

nevermind i just wont use a badge counter in my game since its so complicated

Hey Dont give up!

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)

for some reason whenever i reset it just adds 21 more to my count and theres not even 40 badges