How Would I Award Badges Like This?

First off, I’d like to say I know that you cannot award badges that aren’t yours. And also I’m not the best at scripting too, lol.

Okay, so I need help with this script, how would you award badges in-between two numbers? Lets just say your badge IDs were 2, 7, and 10. I want to award those badges without putting in the IDs to the badges.

Would this even be possible? If it is, how would you do this.

Somebody I know gave me the script below, but we are both confused on how you’d do this.

local badgestart = {1}
local badgeend = {10}
local badgeService = game:GetService("BadgeService")
for badges = badgestart, badgeend, 1 do
end
2 Likes

BadgeService:AwardBadge(plr,Id) - ID would be the badge variable. also badge start and badge end does not need to be a table

Use for i,v loop

local badgeIDS = {1,2,36,592}
local badgeService = game:GetService("BadgeService")

for i,id in next, badgeIDS do
    badgeService:AwardBadge(player,id)
end
3 Likes

You’ll need to provide those badges if you want to award your players with them.
Simply just store your badges in a table.

local badges = {000000,000000,000000}

I suggest using pcalls to check if they dont have those badges already. Since it can fail sometimes.

2 Likes

Thank you for the scripts, and this’ll be hard to explain, but I was wondering if it was possible to go from badge id to badge id and award the badge if it’s in the game. For example, maybe badge 1 to 200 and then award the badge if it’s in the game? I’ve seen it done before but I have zero idea on how to do it. Sorry for the bad explanation too, I just have no idea how to explain it better than that.

1 Like

Do you mean that, if you have n badges, you want to award all of them in your game to your players?

1 Like

Yeah, that’s correct. But is there any way to do it without putting in all the ids? As I said, like going through the badge ids and awarding the badges if the badge id matches one in the game?

Edit: I’m planning on having maybe 10+ badges in multiple different games, it’d be easier to just award them that way without having to add all the ids.

1 Like

Thats not possible, you have to put the ids.
If you are trying to generate random IDs then it will take ages lol

There are like millions-billions of badges in roblox how its gonna generate yours?
If you are going for a complex way then use roproxy then get the all badge of your game then award it

1 Like

Ohh alright. Thanks for telling me.

If you are willing to use the complex way then here it is:

local http = game:GetService("HttpService")

local universeId
local suc,er = pcall(function()
	universeId = http:GetAsync('https://api.roproxy.com/universes/get-universe-containing-place?placeid='..game.PlaceId)
end)

if universeId and suc then
	universeId = http:JSONDecode(universeId)
	universeId = universeId.UniverseId
	local badgesList
	local success,errorr = pcall(function()
		badgesList = http:GetAsync("https://badges.roproxy.com/v1/universes/"..universeId.."/badges")
	end)

	if badgesList and success then
		badgesList = http:JSONDecode(badgesList)
		for i,badge in next, badgesList.data do
			print(badge.id) -- Prints every badge id of your game
		end
	end

	if errorr then error(errorr) end

end

if er then error(er) end

Make sure to enable

1 Like

Thanks, I’ll try it out right now!

I’ve edited the code again, and fixed the universal thing.

1 Like

Thanks! Is there any way to award the badges through that though? Probably not, just wondering.

Well, I’ll just use this for now, thanks! I was wondering on how to do this anyways.

just replace print with:

if badgesList and success then
		badgesList = http:JSONDecode(badgesList)
		for i,badge in next, badgesList.data do
			local badgeService = game:GetService("BadgeService")
            badgeService:AwardBadge(player,badge.id)
		end
end

full code (replace playeradded with anything you want if you dont want players to earn badge by joining)

local http = game:GetService("HttpService")
local badgeService = game:GetService("BadgeService")

local function awardAllBadges(player)
    local universeId
local suc,er = pcall(function()
	universeId = http:GetAsync('https://api.roproxy.com/universes/get-universe-containing-place?placeid='..game.PlaceId)
end)

if universeId and suc then
	universeId = http:JSONDecode(universeId)
	universeId = universeId.UniverseId
	local badgesList
	local success,errorr = pcall(function()
		badgesList = http:GetAsync("https://badges.roproxy.com/v1/universes/"..universeId.."/badges")
	end)

	if badgesList and success then
		badgesList = http:JSONDecode(badgesList)
		for i,badge in next, badgesList.data do
			local got,stat = pcall(function()
                   badgeService:AwardBadge(player,badge.id)
              end)
              if stat then warn(stat) end
		end
	end

	if errorr then error(errorr) end

end

if er then error(er) end
end

game.Players.PlayerAdded:Connect(function(player)
        awardAllBadges(player)
        -- Your other code
end)
1 Like

Hm, It’s still not awarding the badges?

Edit: It might just be because my Studio is being odd? It keeps resetting scripts and shutting down.

I’m curious as to why you’d want to do this - it’d just cause a lot of edge case problems where certain badges aren’t rewarded, you get rate-limited, or you just take forever to actually reward players their badge.

You’d have to put the ID of the badges you want to reward. There are over 2 billion badges on Roblox - to cycle through all 2 billion and find the badges that are associated with your game would take forever.

The solution offered by @Synitx takes the badges from your experience through a web API and rewards them to the player, but this is also prone to being rate limited or just simply puts the opportunity for more edge cases where players aren’t rewarded badges.

In situations like this, it’s best to keep things simple. Badges have IDs for a reason – and that’s so they can be identified and rewarded.

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

local BADGE_IDS = {0, 0, 0}

local function awardAllBadges(player: Player)
    for _, badgeId: number in ipairs(badgeIds) do
        BadgeService:AwardBadge(player, badgeId)
    end
end

Players.PlayerAdded:Connect(awardAllBadges)

This will award a player every badge with an ID in the table BADGE_IDS. If you have two badges with the ID of 8 and 3, the table would then be:

local BADGE_IDS = {8, 3}

Good luck!

2 Likes

This is a very accurate explanation.

Thanks! The reason I wanted to do this is because I had hundreds of games with random badges and just wanted to award them all without having to go through all the IDs and putting them into the script.

I do know somebody who was able to do this, but they wanted the script to be private. I was really just wondering if it was even possible at all!

I don’t think hes looking for storing IDs method.
I’ve already mentioned it here: How Would I Award Badges Like This? - #3 by Synitx