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
local badgeIDS = {1,2,36,592}
local badgeService = game:GetService("BadgeService")
for i,id in next, badgeIDS do
badgeService:AwardBadge(player,id)
end
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.
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.
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
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
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)
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:
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!