Advertisement
Cakey3101

Gamepass Shop Client

May 16th, 2025
530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.83 KB | Source Code | 0 0
  1. local MarketPlaceService = game:GetService("MarketplaceService")
  2. local Players = game:GetService("Players")
  3. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  4.  
  5. local Remotes = ReplicatedStorage.Remotes
  6.  
  7. local TweenGui = require(script.Parent.TweenGui)
  8.  
  9. local Player = Players.LocalPlayer
  10. local PlayerGui = Player.PlayerGui
  11.  
  12. local Gui = PlayerGui:WaitForChild("Shop")
  13. local Frame = Gui.Frame
  14.  
  15. local OpenButton = PlayerGui:WaitForChild("Main").Right.Shop
  16. local ExitButton = Frame.Exit
  17.  
  18. local Container = Frame.Container
  19.  
  20. local Template = Container.Template
  21.  
  22. local GamepassIDS = {
  23.     1222392383,
  24.     1221912385,
  25.     1209923362
  26. }
  27.  
  28. local function PromptGamepass(GamepassID: number, Buy: TextButton)
  29.     local OwnsPass = false
  30.    
  31.     local Success, ErrorMessage = pcall(function()
  32.         OwnsPass = MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, GamepassID)
  33.     end)
  34.    
  35.     if not Success then return end
  36.    
  37.     if OwnsPass then
  38.         Buy.Price.Text = "Owned"
  39.         Buy.Active = false
  40.         Buy.AutoButtonColor = false
  41.     else
  42.         Buy.Active = true
  43.         Buy.AutoButtonColor = true
  44.         MarketPlaceService:PromptGamePassPurchase(Player, GamepassID)
  45.     end
  46. end
  47.  
  48. local function GenerateGamepasses()
  49.     for _, GamepassID in GamepassIDS do
  50.         local OwnsPass = false
  51.  
  52.         local Success, ErrorMessage = pcall(function()
  53.             OwnsPass = MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, GamepassID)
  54.         end)
  55.        
  56.         local GamepassInfo = MarketPlaceService:GetProductInfo(GamepassID, Enum.InfoType.GamePass)
  57.  
  58.         local ClonedTempate = Template:Clone()
  59.         ClonedTempate.Name = GamepassInfo.Name
  60.         ClonedTempate.Icon.Image = `rbxassetid://{GamepassInfo.IconImageAssetId}`
  61.         ClonedTempate.Buy.Price.Text = `{GamepassInfo.PriceInRobux} R$`
  62.         ClonedTempate.Visible = true
  63.         ClonedTempate.ID.Value = GamepassID
  64.         ClonedTempate.Parent = Container
  65.        
  66.         if OwnsPass then
  67.             ClonedTempate.Buy.Price.Text = "Owned"
  68.             ClonedTempate.Buy.Active = false
  69.             ClonedTempate.Buy.AutoButtonColor = false
  70.         else
  71.             ClonedTempate.Buy.Active = true
  72.             ClonedTempate.Buy.AutoButtonColor = true
  73.         end
  74.  
  75.         ClonedTempate.Buy.MouseButton1Click:Connect(function()
  76.             PromptGamepass(GamepassID, ClonedTempate.Buy)
  77.         end)
  78.     end
  79. end
  80.  
  81. local function GamePassPurchased(GamepassID)
  82.     for _, v in Container:GetChildren() do
  83.         if v:FindFirstChild("ID") then
  84.             if v.ID.Value == GamepassID then
  85.                 ClonedTempate.Buy.Price.Text = "Owned"
  86.                 ClonedTempate.Buy.Active = false
  87.                 ClonedTempate.Buy.AutoButtonColor = false
  88.                 break
  89.             end
  90.         end
  91.     end
  92. end
  93.  
  94. OpenButton.MouseButton1Click:Connect(function()
  95.     if Gui.Enabled == true then
  96.         TweenGui.CloseGui(Gui, Frame)
  97.     else
  98.         TweenGui.OpenGui(Gui, Frame)
  99.     end
  100. end)
  101.  
  102. ExitButton.MouseButton1Click:Connect(function()
  103.     TweenGui.CloseGui(Gui, Frame)
  104. end)
  105.  
  106. Remotes.GamePassPurchased.OnClientEvent:Connect(GamePassPurchased)
  107.  
  108. GenerateGamepasses()
Tags: robloxstudio
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement