i have this error that i keep getting for, How do I fix this issue,
Code:
local BadgeId = 83742974923742333344234234234234242
local Works, Error = pcall(function()
if BadgeService:UserHasBadgeAsync(Player.UserId, BadgeId) then
print("Badge Owned")
else
print("Badge Not Owned")
end
end)
if not Works then
print("Failed To Load Badge Status, " .. Error )
end
local Debounce = 1000
local OnDebounce = false
local function AddBadge(BadgeId)
local Works, Error = pcall(function()
if BadgeService:UserHasBadgeAsync(Player.UserId, BadgeId) then
print("Badge Owned")
else
print("Badge Not Owned")
end
end)
if not Works then
print("Failed To Load Badge Status, " .. Error )
end
end
Buttons.MouseButton1Down:Connect(function()
if OnDebounce == false then
OnDebounce = true
AddBadge(Buttons.BadgeId.Value)
wait(Debounce)
OnDebounce = false
end
end)
local ProximityPrompt = script.Parent.ProximityPrompt
local BadgeService = game:GetService("BadgeService")
local Colors = {
Gray = {Color3.fromRGB(30, 30, 30)},
Green = {Color3.fromRGB(0, 204, 6)},
Red = {Color3.fromRGB(214, 0, 7)}
}
ProximityPrompt.Triggered:Connect(function(Player)
if game.Players:FindFirstChild(Player.Name) then
local StarterGui = Player.PlayerGui
local BadgesOwned = StarterGui.BadgesOwned
local SelectedBadge = BadgesOwned.Frame.SelectedBadge
local Badges = BadgesOwned.Frame.Badges
if BadgesOwned.Enabled == false then
BadgesOwned.Enabled = true
end
local LastButton
local Debounce = 1
local OnDebounce = false
local function AddBadge(Button)
if LastButton ~= Button and Player and game.Players:FindFirstChild(Player.Name) then
SelectedBadge.BadgeIcon.Image = "rbxthumb://type=BadgeIcon&id=".. Button:FindFirstChild("BadgeId").Value .."&w=150&h=150"
SelectedBadge.BadgeName.Text = Button:FindFirstChild("Name").Value
SelectedBadge.BadgeStatus.BackgroundColor3 = Colors.Gray[1]
SelectedBadge.BadgeStatus.BadgeStatusText.Text = "Loading Badge Status..."
LastButton = Button
local Works, Results = pcall(function()
if BadgeService:UserHasBadgeAsync(Player.UserId, Button:FindFirstChild("BadgeId").Value) then
SelectedBadge.BadgeStatus.BackgroundColor3 = Colors.Green[1]
SelectedBadge.BadgeStatus.BadgeStatusText.Text = "Badge Owned"
else
SelectedBadge.BadgeStatus.BackgroundColor3 = Colors.Gray[1]
SelectedBadge.BadgeStatus.BadgeStatusText.Text = "Badge Not Owned"
end
end)
if not Works then
SelectedBadge.BadgeStatus.BackgroundColor3 = Colors.Red[1]
SelectedBadge.BadgeStatus.BadgeStatusText.Text = "Failed To Load Badge Status, " .. Results
end
end
end
for i, Buttons in pairs(Badges:GetChildren()) do
if Buttons:IsA "ImageButton" then
if Buttons:FindFirstChild("BadgeId") then
Buttons.Image = "rbxthumb://type=BadgeIcon&id=".. Buttons:FindFirstChild("BadgeId").Value .."&w=150&h=150"
Buttons.MouseButton1Down:Connect(function()
if OnDebounce == false then
OnDebounce = true
AddBadge(Buttons)
wait(Debounce)
OnDebounce = false
end
end)
end
end
end
end
end)
I was firing UserHasBadgeAsync every time the player clicks the button, And the MouseButton connection fires every time the ProximityPrompt gets triggered, And the GUI has “ResetOnSpawn” enabled that’s why