Help on an "all badges" reward

I’ve tried to fix this piece of code to make it so if you have all badges in the game, you get something. But instead, if you have the last badge in the code you get it. Is there anyway to fix this?
(sorry for the messy code)

local BadgeService = game:GetService("BadgeService")
local ServerStorage = game:GetService("ServerStorage")
local trophyNumber = 0

game.Players.PlayerAdded:Connect(function(player)
	if BadgeService:UserHasBadgeAsync(player.UserId, 2128283360) then
		wait(0.01)
		if BadgeService:UserHasBadgeAsync(player.UserId, 2128314658) then
			wait(0.01)
			if BadgeService:UserHasBadgeAsync(player.UserId, 2128314661) then
				wait(0.01)
				if BadgeService:UserHasBadgeAsync(player.UserId, 2128332803) then
					wait(0.01)
					if BadgeService:UserHasBadgeAsync(player.UserId, 2128343571) then
						wait(0.01)
						if BadgeService:UserHasBadgeAsync(player.UserId, 2128357757) then
							wait(0.01)
							if BadgeService:UserHasBadgeAsync(player.UserId, 2128476518) then
								wait(0.01)
						end
					end
				end
			end
		end
		print("PLAYER HAS ALL BADGES")
			game.ServerStorage.Fade_teleporter.Parent = game.Workspace
		print(trophyNumber)
		
		end
		end
end)

You put your actual code in the wrong place.

Try this:

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

--//Controls
local trophyNumber = 0

--//Tables
local BadgeIds = {
	2128283360,
	2128314658,
	2128314661,
	2128332803,
	2128343571,
	2128357757,
	2128476518,
}

--//Functions
local function HasBadge(player, badgeId)
	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 false
	end
	
	return hasBadge
end

local function OwnsAllBadges(player)
	for i, badgeId in ipairs(BadgeIds) do
		local hasBadge = HasBadge(player, badgeId)
		
		if not hasBadge then
			return false
		end
	end
	
	return true
end

Players.PlayerAdded:Connect(function(player)
	if OwnsAllBadges(player) then
		print(trophyNumber)
		print("PLAYER HAS ALL BADGES")
		
		ServerStorage.Fade_teleporter.Parent = workspace
	end
end)
1 Like