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)
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)
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)