How to enable a proximity prompt when the player has a badge?

Hey there! I’m making a hat system where you need a badge to equip it. You go up to the hat and activate a proximity prompt to equip. Problem is, the prompt activates no matter what badge you have, weather you own it or not.

Current Script: (LOCAL)

local player = game.Players.LocalPlayer
local badgeid = 2133603122
local PlayerOwnBadge = game:GetService("BadgeService"):UserHasBadgeAsync(player.UserId, badgeid)

if PlayerOwnBadge then
	workspace.Pan.ProximityPrompt.Enabled = true
else
	workspace.Pan.ProximityPrompt.Enabled = false
end

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

The badge id was a test, its a badge I don’t own. The real Id is 1971513294383685

UserHasBadgeAsync is an asynchronous function.

local Players = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")
local player = Players.LocalPlayer
local badgeId = 2133603122

local function checkBadge()
    local success, hasBadge = pcall(function()
        return BadgeService:UserHasBadgeAsync(player.UserId, badgeId)
    end)

    if success and hasBadge then
        workspace.Pan.ProximityPrompt.Enabled = true
    else
        workspace.Pan.ProximityPrompt.Enabled = false
    end
end

-- Call the function to check the badge
checkBadge()

I got it to work, the problem was on the other hats it made the pan enable as well because I had their badges. I’ll still give you the solution though!

1 Like

Thanks! You should definitely still wrap it in a pcall, otherwise it may break if Roblox’s BadgeService is down.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.