Hello Develepers, i am working on a Script, that show’s the Player an imagebutton ( which IS in the StarterGUI in a frame ) if the player has a certain badge, i already know IT works with a Gamepass, but does that also Work with a badge ?
( If this IS in the wrong category please Tell me )
if a script can access a badge and perform a certain function if the player has the badge, then that’s what I meant (sorry, I don’t speak English very well, which is why I could only roughly translate the message in the picture, I write most Things in the Develeperforum with the help of a translator) (maybe you can send me the link to the website, were you have found the informations )
local BadgeService = game:GetService("BadgeService")
local badgeId = 0 --replace with your badge id
local userId = 0 --replace with player user id
--you may want to pcall this if you want to ensure it wont error/break the code
if BadgeService:UserHasBadgeAsync(userId, badgeId) then
print("Badge "..badgeId.." owned by "..userId.."!")
end
Thank you for the scripts and the answers but i mean something like this:
local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local badgeID = 123456789 -- I will change the ID soon
local function checkBadge(player)
local success, hasBadge = pcall(function()
return BadgeService:UserHasBadgeAsync(player.UserId, badgeID)
end)
if success and hasBadge then
local playerGui = player:WaitForChild("PlayerGui")
local screenGui = playerGui:FindFirstChild("OpenFrame")
if screenGui then
local haveBadgeFrame = screenGui:FindFirstChild("havebadge")
if haveBadgeFrame then
haveBadgeFrame.Visible = true
end
end
else
warn("Failed to check badge or player does not have the badge")
end
end
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
checkBadge(player)
end)
end)
If something is one please tell me what won’t work ( i have not try it jet)
This is making the frame visible, not the image button.
At least, from what I’m understanding, the image button is in the frame, and you want to make the image button visible.
I’ve read the script, and it turns out that that is probably intentional.