Trying to make a badgeowned index

I am trying to make a BadgeOwned index, it is basically a GUI that is supposed to display the images only if the player owns the Badge. So it changes the image color to 0,0,0 and if they own it it changes it to 255,255,255
The issue is the script wont work… here’s the code.

local ID = 0 --left as example to post in devforum
local player = game.Players.LocalPlayer
 local MarketplaceService = game:GetService("MarketplaceService")
 
script.Parent.Parent.Parent.Parent.btnIndex.MouseButton1Click:Connect(function()
    if MarketplaceService:PlayerOwnsAsset(player.UserId, ID) then
        script.Parent.Icon.ImageColor3 = Color3.new(255, 255, 255)
    else
        script.Parent.Icon.ImageColor3 = Color3.new(0, 0, 0)
    end
end)
2 Likes

Not quite sure, but there’s a specific service for awarding badges, and checking if the player has it.

2 Likes

Are you sure the id is correct?
Have you considered using BadgeService:UserHasBadgeAsync()?
(Note that it can only be used in server scripts so you will need to use remotes)

Edit: @xBeepBoop beat me to it

2 Likes

Trying that right now,

local ID = 0
local player = game.Players.LocalPlayer
 local BadgeService = game:GetService("BadgeService")
 
script.Parent.Parent.Parent.Parent.btnIndex.MouseButton1Click:Connect(function()
    if BadgeService:UserHasBadgeAsync(player.UserId, ID) then
        script.Parent.Icon.ImageColor3 = Color3.new(255, 255, 255)
    else
        script.Parent.Icon.ImageColor3 = Color3.new(0, 0, 0)
    end
end)

As @Amiaa16 said:

Edit: Whoops! It does work locally.

No it worked locally, as most of this code is local. The solution worked.

1 Like

@Kensizo Since, after a day you found your solution, you might wanna add the solution add a solution to your post.