Gui Visible If Not OwnBadge

I make gui that only visible if not own badge and if own then visible can somebody help me because i got error in this local script.

local BadgeService = game:GetService(“BadgeService”)

local Players = game:GetService(“Players”)

local badgeID = 2124695926

local OwnBadge = BadgeService:UserHasBadgeAsync(Players.UserId, badgeID)

local locked = game.StarterGui.Halo.MainFrame:WaitForChild(“Purple Frame”)

local main = locked.locked

if Players.OwnBadge then

main.Visible = false

if not Players.OwnBadge then

main.Visible = true

end

Thanks Developer!

1 Like

You are not indexing a LocalPlayer so it errors

Players.LocalPlayer.UserId

Im a bit confuse where should i put that? hmm

LocalScript:

local BadgeService = game:GetService("BadgeService")

local Players = game:GetService("Players")

local Player = Players.LocalPlayer

local badgeID = 2124695926

local OwnBadge = BadgeService:UserHasBadgeAsync(Player.UserId, badgeID)

local locked = Player:WaitForChild("PlayerGui").Halo.MainFrame:WaitForChild("Purple Frame")

local main = locked.locked

local function CheckForBadge()
if OwnBadge == true then
	main.Visible = false
end
if OwnBadge == false then
	main.Visible = true
  end
end	

CheckForBadge()
3 Likes

Thanks! for helping me again thank you.