How would I make this check every 5 seconds?

  1. What do you want to achieve? I would like for this script to refresh every second

  2. **What is the issue?**the issue is if I get a badge the leaderboard doesn’t refresh and just stays as its previous score which leads me into rejoining

  3. What solutions have you tried so far? I tried doing an “if true do” and stuff like that but didn’t work

game.Players.PlayerAdded:Connect(function(plr)
	wait(0.5)
	local BadgeService = game:GetService("BadgeService")
	local badgeIds = {2124871551,2124871927,2124871927,2124874652,2124875134,2124875135,2124875283,2124883537,2124883540,2124883811,2124883814,2124883850,2124883955,2124883958,2124902920,2124902921,2124902922,2124885305,2124904543,2124903302,2124903285,2124904556,2124903961,2124903965,2124903963,2124906387,2124907283,2124907055,2124907311} --Put badge ids here
	for _, id in next, badgeIds do
		if BadgeService:UserHasBadgeAsync(plr.UserId, id) then  -- checks if user has badge
			plr.leaderstats.Exorics.Value = plr.leaderstats.Exorics.Value +1 -- if so then adds 1
			
		end
	end
end)

(note: the wait(0.5) is so that it works because the leader stats load after the script works so

while wait(5) do

end
game.Players.PlayerAdded:Connect(function(plr)
while true do
  wait(5)
	wait(0.5)
	local BadgeService = game:GetService("BadgeService")
	local badgeIds = {2124871551,2124871927,2124871927,2124874652,2124875134,2124875135,2124875283,2124883537,2124883540,2124883811,2124883814,2124883850,2124883955,2124883958,2124902920,2124902921,2124902922,2124885305,2124904543,2124903302,2124903285,2124904556,2124903961,2124903965,2124903963,2124906387,2124907283,2124907055,2124907311} --Put badge ids here
	for _, id in next, badgeIds do
		if BadgeService:UserHasBadgeAsync(plr.UserId, id) then  -- checks if user has badge
			plr.leaderstats.Exorics.Value = plr.leaderstats.Exorics.Value +1 -- if so then adds 1
			
		end
	end
end
end)

You can just do while wait(5) do, you don’t need to add a wait into a while true

basically no difference, both of them work as intended

it duplicated them for some reason?

Screen Shot 2022-01-11 at 7.44.53 PM

and after it does that it just wont work again

could you send the whole script?

game.Players.PlayerAdded:Connect(function(plr)
	while true do
	wait(5)
		wait(0.5)
		local BadgeService = game:GetService("BadgeService")
		local badgeIds = {2124871551,2124871927,2124871927,2124874652,2124875134,2124875135,2124875283,2124883537,2124883540,2124883811,2124883814,2124883850,2124883955,2124883958,2124902920,2124902921,2124902922,2124885305,2124904543,2124903302,2124903285,2124904556,2124903961,2124903965,2124903963,2124906387,2124907283,2124907055,2124907311} --Put badge ids here
		for _, id in next, badgeIds do
			if BadgeService:UserHasBadgeAsync(plr.UserId, id) then  -- checks if user has badge
				plr.leaderstats.Exorics.Value = plr.leaderstats.Exorics.Value +1 -- if so then adds 1

			end
		end
	end
end)

has it done this before the while loop?

No, as i remember I’m pretty sure it didn’t work at all and broke the script

game.Players.PlayerAdded:Connect(function(plr)
while true do
  wait(5)
	wait(0.5)
	local BadgeService = game:GetService("BadgeService")
	local badgeIds = {2124871551,2124871927,2124871927,2124874652,2124875134,2124875135,2124875283,2124883537,2124883540,2124883811,2124883814,2124883850,2124883955,2124883958,2124902920,2124902921,2124902922,2124885305,2124904543,2124903302,2124903285,2124904556,2124903961,2124903965,2124903963,2124906387,2124907283,2124907055,2124907311} --Put badge ids here
	for _, id in next, badgeIds do
		if BadgeService:UserHasBadgeAsync(plr.UserId, id) then  -- checks if user has badge
            print("check")
			plr.leaderstats.Exorics.Value += 1 -- if so then adds 1
			
		end
	end
end
end)

Try pasting that in and show me the output

i need to see the output to see how many times it printed check to see where the problem is at

Screen Shot 2022-01-11 at 8.08.18 PM


Screen Shot 2022-01-11 at 8.08.46 PM

how many badges are there? it duplicates the badge points?

there are 29 badges put there and i own 17 and yes i think they are duplicating becasue it doesnt already check if they already own it and if its already in their leader stats

can you explain what you want the script to do?

I want the script to be able to show a badge counter of the badges but refresh every second so you don’t need to rejoin to see the current badges you own

it wouldnt work because the loop is infinite, so you’d have to add some changes

How would I add those changes?