Award a badge only once owning others

Hello!

I need some help with a script. I want my script to award a badge, once a player has collected the specific other badges.

A bit like Jailbreak’s MVP Badge

I assume I need to check the player for the specific badges, and then award them the badge for collecting all.

I have no idea how to do this though? So if anyone could help, it would greatly appreciated. :slight_smile: :upside_down_face:

3 Likes

What I would do is when assigning those specific badges check if the player has the other specific badges and if they do then award it

And I’d do this how? You think you could draft a script that would do this?

How helpful! sarcasm __________

Did you scroll down to the part that says “Checking Earned Badges”

Yes lol. This was my script, tell me if this will work:

local badgeService = game:GetService("BadgeService")
local MVPBadgeId = 1234567890
local BadgeNeeded1id = 1234567890
local BadgeNeeded2id = 1234567890
local BadgeNeeded3id = 1234567890
local BadgeNeeded4id = 1234567890
local function onPlayerAdded(player)
	-- Check if the player has the badge
	local success1, hasBadgeS = pcall(badgeService.UserHasBadgeAsync, badgeService, player.UserId, BadgeNeeded1id)
	local success2, hasBadgeB = pcall(badgeService.UserHasBadgeAsync, badgeService, player.UserId, BadgeNeeded2id)
	local success3, hasBadgeA = pcall(badgeService.UserHasBadgeAsync, badgeService, player.UserId, BadgeNeeded3id)
	local success4, hasBadgeT = pcall(badgeService.UserHasBadgeAsync, badgeService, player.UserId, BadgeNeeded4id)

if hasBadgeS, hasBadgeB, hasBadgeA, hasBadgeT then
		badgeService:AwardBadge(player.UserId, MVPBadgeId)
end)

I’m guessing you mean something like this.

local badges = {"123", "456"}
local StartBadgeID = "789"
local BS = game:GetService("BadgeService")
if BS:UserHaSBadgeAsync(StartBadgeID, game.Players.LocalPlayer.UserId) then
	print("Has the start badge!")
	for i, v in ipairs(badges) do
		if not BS:UserHasBadgeAsync(v, game.Players.LocalPlayer.UserId) then
			BS:AwardBadge(v, game.Players.LocalPlayer.UserId)
		end
	end
end
1 Like

Basically, I have 4 badges. They all need to be owned in order to get the completion badge.

Is ‘StartBadge’ the one awarded if you have all 4 ‘badges’

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

--//Controls
local MVPBadgeID = 000000000

--//Tables
local BadgeIDsNeeded = {
	000000000,
	000000000,
	000000000,
	000000000
}

--//Functions
Players.PlayerAdded:Connect(function(player)
	local hasFirstBadge = false
	local hasSecondBadge = false
	local hasThirdBadge = false
	local hasFourthBadge = false
	
	for i, badgeId in ipairs(BadgeIDsNeeded) do
		local success, hasBadge = pcall(function()
			return BadgeService:UserHasBadgeAsync(player.UserId, badgeId)
		end)

		if not success then
			warn("Error while checking if player has badge!")
			
			return
		end

		if hasBadge then
			if i == 1 then
				hasFirstBadge = true
			elseif i == 2 then
				hasSecondBadge = true
			elseif i == 3 then
				hasThirdBadge = true
			elseif i == 4 then
				hasFourthBadge = true
			end
		end
	end
	
	if hasFirstBadge and hasSecondBadge and hasThirdBadge and hasFourthBadge then
		local success, result = pcall(function()
			return BadgeService:AwardBadge(player.UserId, MVPBadgeID)
		end)

		if not success then
			warn("Error while awarding badge:", result)
		elseif not result then
			warn("Failed to award badge.")
		end
	end
end)
5 Likes

No, all of the items in the badges table are awarded if they have the StartBadge. Here’s what I think you mean now;

local badges = {"123", "456", --[[etc]] }

local CompleteBadge = "1234"

local BS = game:GetService("BadgeService")

local Count = 0
local RequiredCount = 4

for i, v in ipairs(badges) do
	if BS:UserHasBadgeAsync(game.Players.LocalPlayer.UserId, v) then
		Count += 1
	end
end

if Count == RequiredCount then
    if not BS:UserHasBadgeAsync(game.Players.LocalPlayer.UserId, CompleteBadge) then
	    BS:AwardBadge(game.Players.LocalPlayer.UserId, CompleteBadge)
    end
end
1 Like

Thanks! @Katrist just pipped you too the post! Thanks soo much though for responding to my message. I’m sure it works.

Thanks! Everything is working!

1 Like

No worries, for the future please dont dm me if you have an issue. If I wanted to help people I would have found this by myself.

No problem, have a good day.

30

1 Like

Sorry! But there’s nothing on your profile, but thanks for taking time to help me!

2 Likes

I have my Discord and Twitter listed there.

1 Like

Okay. Well I’m sorry. Thanks for your help!

2 Likes