Help making a badge GUI

Hello!

I was wondering if anybody could help me create a script for a gui that will only display a button on screen if the user owns a specific game badge.

The badge ID is: 2124805736 [if its needed]

I want it so alpha testers can have a special vehicle spawn menu that nobody else has access to and using a badge method was the easiest method I could think of.

Appreciate all the help!

1 Like

You can use UserHasBadgeAsync to check for badge ownership. If this function returns true then you can set Enabled to true on your ScreenGui (or if it’s a Frame, Visible). You can do a bit of research on other API via the Developer Hub as you need.

Well, That’s Kinda Easy To Create, Here It Is:

Script:

local BadgeService = game:GetService("BadgeService")
local BadgeId = 2124805736 -- Your Own Badge Id

--[[
local function awardBadge(player, badgeId)
	-- Fetch badge information
	local success, badgeInfo = pcall(function()
		return BadgeService:GetBadgeInfoAsync(badgeId)
	end)
	if success then
		-- Confirm that badge can be awarded
		if badgeInfo.IsEnabled then
			-- Award badge
			local awarded, errorMessage = pcall(function()
				BadgeService:AwardBadge(player.UserId, badgeId)
			end)
			if not awarded then
				warn("Error while awarding badge:", errorMessage)
			end
		end
	else
		warn("Error while fetching badge info!")
	end
end
--]]

game.Players.PlayerAdded:Connect(function(Player)
	--awardBadge(Player, BadgeId)
	
	local success, HasBadge = pcall(function()
		return BadgeService:UserHasBadgeAsync(Player.UserId, BadgeId)
	end)
	
	if success then
		game.ReplicatedStorage.VisibleButton:FireClient(Player)
	else
		warn("This Player Doesn't Have The Badge")
	end
end)

LocalScript:

game.ReplicatedStorage.VisibleButton.OnClientEvent:Connect(function()
	script.Parent.TextButton.Visible = true
end)

I Hope This Reply Helps You.

5 Likes

Is there anyway to have a GUI appear when the badge is given to the player?