Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make a GUI that only shows when you own a gamepass?

So i'm making a game and i'm trying to make a teleport button only show up when the player owns a gamepass. I'm very new to scripting and the only tutorial out there for it is one from over a year ago. I tried changing it to work with MarketPlaceService but with no luck.

Here is the script if anyone is able to fix it.

local id = 5549229

game.Players.PlayerAdded:connect(function (plr)
 if game:GetService('MarketplaceService'):PlayerOwnsAsset(plr,id)then
  plr.PlayerGui.teleportGUI.Teleport.Visible = true
 end
end)

Thanks :)

1 comment

0

you could change it up a bit and have it so that the gui is enabled by default and store it in server storage and then when a player joins the game check if they have the game pass, and if they do, add the gui to their screen.

1 answer

✓ Accepted answer

You're correct with how you are writing it, yet it's formatted too weirdly, it confused the Script, try writing it like this?

local Players = game:GetService("Players")
local MarketPlaceService = game:GetService(MarketPlaceService")
local GamepassId = 5549229

Players.PlayerAdded:Connect(function(Player) --// Connect with a lowercase has been deprecated too, also there shouldn't be a space between the parentheses 
   if (MarketPlaceService:PlayerOwnsAsset(Player, GamepassId)) then
      Player:WaitForChild("PlayerGui").teleportGUI.Teleport.Visible = true --//It's best to be precautious as the Folder may not load as fast as the Script runs 
   end
end)

Hope this fixed your issue

2 comments

0

Make sure your Script is also Local

0

Either inside of the GuiObject, or inside of PlayerStarterScripts

This discussion is preserved as it was. New answers, comments, and votes are closed.