#BadgeService:UserHasBadgeAsync always returns n

1 messages · Page 1 of 1 (latest)

spiral tinsel
#

can someone please tell me where i went wrong with this code?

LocalScript (GUI)

local remfunc = game:GetService("ReplicatedStorage").UpdateNames
local list = script.Parent:WaitForChild("ScreenGui").List.List
for _, v in pairs(list:GetChildren()) do
    if v:IsA("Frame") then
        local GameName = game:GetService("MarketplaceService"):GetProductInfo(v.Name).Name
        local badgeID = v:FindFirstChildWhichIsA("UICorner")
        if badgeID then
            local success, result = remfunc:InvokeServer(tonumber(badgeID.Name))
            print(v:FindFirstChild("Name_Desc").Text .. " " .. tostring(result))
            if success and result == true then
                v.BackgroundColor3 = Color3.fromRGB(20, 36, 44)
            end
        end
        local text = list:FindFirstChild(v.Name).GameName
        text.Text = GameName
    end
end

Script (BadgeService)

local badgeS = game:GetService("BadgeService")

local event = game:GetService("ReplicatedStorage"):WaitForChild("UpdateNames")

event.OnServerInvoke = (function(player, name)
    local maxtries = 3
    local tries = 0
    local success, response
    repeat
        tries += 1
        success, response = pcall(function()
            badgeS:UserHasBadgeAsync(player.UserId, name)
        end)

        if not success then
            warn("didnt work on try" .. tostring(tries) .. " because " .. response)
        end
    until success or tries >= maxtries
    return success, response
end)

v.name in the local script is a placeID
and the uicorner.name is the badgeID

tribal elbow
#

Inside the pcall function, you needa return the value. Otherwise response always will be nil

#
success, response = pcall(function()
    return badgeS:UserHasBadgeAsync(player.UserId, name)
end)```
#

Like above

spiral tinsel
#

oh

#

lol

#

ty

tribal elbow
#

Also, store the placeId and badgeId in Data storing instances (Int value in your case). It'll help you stay organized and not make the code complicated.

#

Solved✅