How to make a leaderstats badge

I am trying to make a badge that will award the player when they earn 10 rebirths.

This is the script I tried and it didn’t work. (I am new to scripting so idk if I was even close to getting it… I was just trying anything)

game:GetService('Players').PlayerAdded:Connect(function(player)
	while true do
		if player.leaderstats.Rebirths.Value == 10 then
			game:GetService('BadgeService'):AwardBadge(player.UserId, 2150680559)
		else
		wait(30)	
		return
		end
		
		
		
	end
end)
2 Likes

With return, you are essentially just ending the Event, and the Loop inside of it, also, I would recommend you use a loop for this occassion as:

  1. Waste of Resources

  2. Code Bloat

  3. There is a much more efficient way

use .Changed when checking for Rebirths, instead of trying to wait every 30 seconds to see if they meet the requirements, use .Changed to check for when the change actually happens

ValueBase.Changed:Connect(function(value) -- fires when there is a change
    if value >= 10 then -- if the requirements are met
        BadgeService:AwardBadge(UserId, BadgeId) -- award badge
    end
end) -- end of Event
1 Like