Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
Edited 5 years ago

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

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. SteamG00B 1633 — 5y

1 answer

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
5 years ago

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

0
Make sure your Script is also Local Ziffixture 6913 — 5y
0
Either inside of the GuiObject, or inside of PlayerStarterScripts Ziffixture 6913 — 5y
Ad

Answer this question