I am making a “find the morphs” type of game and have found a problem in making a morph button visible if user owns a certain badge corresponding to the morph. I have tried UserHasBadgeAsync and have gotten back results like “UserHasBadgeAsync: failed due to empty response”, and “Too many requests” after morphing for 1 or 2 times the morph buttons disappear along with the error messages showing
Did you do it like
if game:GetService("BadgeService"):UserHasBadgeAsync(UserID, BadgeId) then
? You need to get the UserID of who you are checking, as well as the badge id
Edit: Here is how to use it from the Roblox docs page here . Also you should pcall this function as yes, it can error. You can see how roblox pcalled the function in the doc above
game.Players.PlayerAdded:Connect:(function(Player) if game:GetService("BadgeService"):UserHasBadgeAsync(Player, [BadgeId]) then --Do stuff
You can mark me as correct, works on both type of script(local script and normal script)
ive tried to do this but the local script doesn’t run
Non-local script: (with all error checking).
in ServerScriptService to vs hacking…
You may need to use a remote event. But this can do all your badges.
AwardBadge(player, badge_ID#)
local function AwardBadge(player, badge)
local success, hasBadge = pcall(function()
return BadgeService:UserHasBadgeAsync(player.UserId, badge)
end) if not success then warn("Error while checking if player has badge!")
return
end
if hasBadge then print("Player has badge " .. badge )
else
local success, badgeInfo = pcall(function()
return BadgeService:GetBadgeInfoAsync(badge)
end)
if success then
if badgeInfo.IsEnabled then
local awarded, errorMessage = pcall(function()
BadgeService:AwardBadge(player.UserId, badge)
end)
if not awarded then warn("Error while awarding badge:", errorMessage)
else print("Awarding badge")
end
end
else warn("Error while fetching badge info!")
end
end
end
Ive tried to run the exact script roblox is using changing the output and the badgeId of course but the script doesn’t seem to run at all.
I’m trying to check if the player joining the game has a specific badge and if he does a Morph button is enabled for him.
This one is in ServerScriptService and gives items if they have a gamepass.
I’m sure you can covert it to a badge …
local Players = game:GetService("Players")
local MarketPlaceService = game:GetService("MarketplaceService")
local gamepassID = 11111111 -- BlueGmePass -- Sport Drink on spawn
function Spawned(player)
task.wait(1.1) local HasGamepass = false
local success, message = pcall(function()
HasGamepass = MarketPlaceService:UserOwnsGamePassAsync(player.userId, gamepassID)
end)
if not success then
warn("Checking Gamepass "..tostring(message))
return
end
if HasGamepass == true then
game.ServerStorage.Tools.SpeedDrink2:Clone().Parent = player.Backpack
end
end
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
Spawned(player)
end)
end)
i’m pretty sure its server sided, im trying to make a gui visible if they own something and I don’t want it to show for everyone if only one person owns the badge
just examples of ways to see if the badge is owned … you’ll have to edit/take what you need.
ive tried editing it and taking and it doesn’t seem tow work, I’m wondering if I should put it under the actually GUI button or somewhere else
it do works.Maybe you don’t own the badge I think.Show me the full code of the script you made
it does work but at a larger scale(30+ morphs it gives me output UserHasBadgeAsync: failed due to empty response”, and “Too many requests”)
thats after i morph 1 or 2 times at least and all the morphs become enabled even if I don’t have it
local starterGUI = game:GetService("StarterGui")
local morph = starterGUI.MorphGui.Morph.ScrollingFrame["Frozen Wubbox"].Morph.BadgeOnly
local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local badgeId = 2147578248 -- Change this to your badge ID
local function onPlayerAdded(player)
-- Check if the player has the badge
local success, hasBadge = pcall(function()
return BadgeService:UserHasBadgeAsync(player.UserId, badgeId)
end)
-- If there's an error, issue a warning and exit the function
if not success then
warn("Player Does Not Have Badge!")
return
end
if hasBadge then
script.Parent.Visible = true
end
end
-- Connect "PlayerAdded" events to the "onPlayerAdded()" function
Players.PlayerAdded:Connect(onPlayerAdded)