Badge Granted At X Currency Help

I Need A Badge Granted At A Certain Amount Of Coins
Its Called Coins The Leader stat But I Only Find Tutorials Making New Leader stats
I Have One In Game Called Coins.
How do i make it where i get a certain amount and get a badge.

Read up on BadgeService on the Developer Hub. You can do something like:

if Player.Coins.CoinAmount == 1000 then
  BadgeService:AwardBadge(Player.UserId,your badge id)
end
2 Likes

if i put that in server script service would it work if i made the badge id mine ?
ive always struggled with this.

1 Like

also is this equal to wouldnt that not grant it if they went a tiny bit over.

1 Like

If that’s not what you want:

if Player.Coins.CoinAmount >= 1000 then --If they either have 1000 coins OR they have more then:
  BadgeService:AwardBadge(Player.UserId,your badge id)
end
2 Likes

so this in server script service will work

1 Like

If you have the rest of your code, yes.

1 Like

Yes. You have to put the ID of a badge you created.

Actually no. You’re not getting any value.

Here:

if Player.Coins.CoinAmount.Value >= 1000 then --If they either have 1000 coins OR they have more then:
  BadgeService:AwardBadge(Player.UserId,your badge id)
end
2 Likes

Use this:

--//Services
local Players = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")

--//Variables
local BadgeId = 0000000 -- Replace with your badge ID

--//Functions
Players.PlayerAdded:Connect(function(player)
 player.leaderstats.Coins:GetPropertySignalChanged("Value"):Connect(function()
  if player.leaderstats.Coins.Value >= 1000 then
   BadgeService:AwardBadge(player.UserId, BadgeId)
  end
 end)
end)
2 Likes

if i had several badges would i duplicate this script

1 Like

Just duplicate the if statement and add more badgeId variables.

1 Like

For example:

--//Services
local Players = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")

--//Variables
local BadgeId1 = 0000000 -- Replace with your badge ID
local BadgeId2 = 0000000 -- Replace with your badge ID

--//Functions
Players.PlayerAdded:Connect(function(player)
 player.leaderstats.Coins:GetPropertySignalChanged("Value"):Connect(function()
  if player.leaderstats.Coins.Value >= 1000 then
   BadgeService:AwardBadge(player.UserId, BadgeId1)
  end
  if player.leaderstats.Coins.Value >= 10000 then
   BadgeService:AwardBadge(player.UserId, BadgeId2)
  end
 end)
end)
2 Likes

Doesnt work and also doesnt that mean that if they went over 1000 they still wouldnt get it for example
they got 5 coins and it went from 997-1001 they wouldnt get it.
it also just doesnt work.

Do you have a badge id? If you do, change the value of the BadgeId variable to the badge id you have.
Also, what’s your currency’s name, and do you place it under leaderstats?

leaderstats yes , coins and also yes i did the badge id right.

Do you get any errors in the output?

It would work and >= is the greater than or equal to operator so even if the value of the coin stat skipped 1000 coins the badge would still be awarded.

local Players = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")

local BadgeId1 = 0 -- Replace with your badge ID
local BadgeId2 = 0 -- Replace with your badge ID

Players.PlayerAdded:Connect(function(player)
	local leaderstats = player:WaitForChild("leaderstats")
	local coins = leaderstats:WaitForChild("Coins")
	coins.Changed:Connect(function(value)
		if value >= 1000 then
			BadgeService:AwardBadge(player.UserId, BadgeId1)
		end
		if value >= 10000 then
			BadgeService:AwardBadge(player.UserId, BadgeId2)
		end
	end)
end)

This goes without saying but this would need to be in a server script inside ServerScriptService or some other suitable location, also this won’t work if you’re changing the “Coins” stat from a local script as that won’t replicate to the server.

1 Like

It would work because I tried it and it did.
Please try it before saying “it also just doesn’t work.”

local BadgeService = game:GetService("BadgeService")
local BadgeID = 000000 -- Replace with your BadgeId!

game.Players.PlayerAdded:Connect(function(Player)
        if Player.leaderstats.Coins.Value >= 1000 then
        BadgeService:AwardBadge(Player.UserId, BadgeID)
   else
       return Player.leaderstats.Coins.Value
    end
end)
1 Like