Problems with Overhead GUI

I have been having problems with my code not displaying a tag over my head when I own the game pass. I have tried multiple different ways such as using different gamepasses but none of them work. Can anyone help me?

PlayerOwnsAsset is not how you resolve if a player has a game pass. Use UserOwnsGamePassAsync.

2 Likes

I replaced PlayerOwnsAsset With UserOwnsGamePassAsync but it still doesn’t work.

Aside from what was already said, you also need to adornee your gui to the part you want to bind it to.

BillboardGui.Adornee = character.Head

Looks to me like you are not setting the BillboardGui’s Adornee property anywhere. You must set this property to the part you wish it to follow. Simply parenting it to a part is not enough.

How much have you debugged it? What line is it failing to get to that you expect it to?

5 Likes

Everything seems fine but it doesn’t show up in game. I used
if player.Name == “AlmostADemon” then
instead of
if game:GetService(“MarketplaceService”):PlayerOwnsAsset(player,5298866) then
And it works but the game pass version does not.

UserOwnsGamePassAsync requires a UserId, not the player object itself. It won’t work otherwise.

And as stated numerous times above, you have to set the BillboardGui’s Adornee.

1 Like
local billboardGui = game:GetService("ServerStorage"):FindFirstChild("BillboardGui")

game:GetService("Players").PlayerAdded:Connect(Plr)
    Plr.CharacterAdded:Connect(function(Char)
        wait(0.1)
        if game:GetService("MarketplaceService"):UserOwnsGamepassAsync(Plr.UserId, 529886) then
            local ClonedGui = billboardGui:Clone()
            ClonedGui.Parent = Char.Head
            ClonedGui.TextLabel.Text = "YT"
            ClonedGui.TextLebel.TextColor3 = Color3.fromRGB(45, 255, 90)
            ClonedGui.Adornee = Char.Head
        end
    end)
end)

Try this code :smile:

It says Expected ,got’end’
in which I assume there was an extra end in that code so I removed it and the code still doesn’t work.

1 Like

There should be two ends ending in ) and one that does not.

1 Like

Here is the fixed code:

local billboardGui = game:GetService("ServerStorage"):FindFirstChild("BillboardGui")

game:GetService("Players").PlayerAdded:Connect(function(Plr)  -- Forgot to add the function here.
    Plr.CharacterAdded:Connect(function(Char)
        wait(0.1)
        if game:GetService("MarketplaceService"):UserOwnsGamepassAsync(Plr.UserId, 529886) then
            local ClonedGui = billboardGui:Clone()
            ClonedGui.Parent = Char.Head
            ClonedGui.TextLabel.Text = "VIP"
            ClonedGui.TextLebel.TextColor3 = Color3.fromRGB(45, 255, 90)
            ClonedGui.Adornee = Char.Head
        end
    end)
end)
1 Like
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local MarketplaceService = game:GetService("MarketplaceService")

local OverheadGui = ServerStorage.BillboardGui

Players.PlayerAdded:Connect(function (Player)
    Players.CharacterAdded:Connect(function (Character)
        local success, result = pcall(MarketplaceService.UserOwnsGamePassAsync, MarketplaceService, Player.UserId, 529886)
        if success and result then
            local Overhead = BillboardGui:Clone()
            OverheadGui.TextLabel.Text = "VIP"
            OverheadGui.TextLabel.TextColor3 = Color3.fromRGB(45, 255, 90)
            OverheadGui.Adornee = Character.Head
            OverheadGui.Parent = Character
        end
    end)
end)

Some pointers Lots of pointers I’d like to give, both to code that was posted before my own and in general. Normally I do not like to write out entire blocks of code for others, but since it was already done, I just refurbished the code.

  • Using a wait statement after CharacterAdded is unnecessary. Cloning is a synchronous operation and CharacterAdded fires as in when the character is set up and assigned.
  • Try indexing services as local variables, should you need them later into your script.
  • The name convention for “game pass” is two words. Game pass, not gamepass.
  • UserOwnsGamePassAsync is a web call internally. You should wrap any kind of internal web calls in pcall so that errors can be caught if the call fails.
  • Use better names. “BillboardGui” is ambiguous for an object that you’re storing directly under ServerStorage. Always use clear and concise naming for variables. It helps you and if you have any, your collaborators as well.
  • If you’re going for a pre-setup object that doesn’t need to be modified later, set the properties. You can skip using code space to edit something that can be already be set at runtime.
  • Set your properties first before the Parent of an object.
  • Proofread your code and do debugging. Often at times, some code errors may be an oversight on your behalf. As well, when someone suggests code, play around with it a bit - don’t copy it raw into Studio, test it and say “it doesn’t work” immediately after (that’s if the code isn’t intended to be utilised this way).
  • Search the DevForum and the Developer Hub. Often, these two locations already hold answers to your problems as asked by others.
  • Check everything. What if your only “error” happened to be that the BillboardGui’s Enabled property was set to false!?
  • Search the Developer Console when running a test server. Your console could be spitting out errors regarding what’s happening with your code.
  • Place prints around your code and see what prints and what doesn’t. Printing helps a lot to set a checkpoint as to where your code is and isn’t working.
  • In the future, in regards to one of your attempts to play with your code, any kind of work that has to do explicitly with getting a Player for a permission-based asset, always do it by UserId. Username can be changed, while UserId cannot. You can convert a username to a UserId by using GetUserIdFromNameAsync. Whether your username changes or not, this feeds a username to the function and spits back out the UserId associated with this username. It’s internally a web call, so remember to pcall it.
5 Likes