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.
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.
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)