How can I make gamepasses clone using table values - Roblox Luau

73 Views Asked by At

My module script

local module = {
    ["DisplayProduct"] = {
        ["Name"] = "ADMIN",
        ["Image"] = 0,
        ["Price"] = "150,000",
        ["GamepassId"] = 0,
    },
    ["testproduct"] = {
        ["Name"] = "Harry Potter",
        ["Image"] = 0,
        ["Price"] = "NOT FOR SALE",
        ["GamepassId"] = 0,
        active = true
    }
}

return module

My local script

if Gamepasses.testproduct.active == true then
    local zz = GamepassFrame
    zz.name.Text = Gamepasses.testproduct.Name
    zz.ProductImage.Image = Gamepasses.testproduct.Image
    zz.Purchase.price.Text = Gamepasses.testproduct.Price
    zz.Parent = Container.Gamepasses
    
    zz.ProductImage.MouseButton1Click:Connect(function()
        MarketplaceService:PromptGamePassPurchase(player, Gamepasses.testproduct.GamepassId)
    end)
end

I'm trying to detect if a table's value named "active" is true or false, if true it clones a frame and fills in the information using the table values, but I'm very unsure of how to create this.

Any help would be appreciated!

1

There are 1 best solutions below

0
RobuxTRex On

What I'm getting at here is you have the info of a gamepass/dproduct in a module script, and if active is true, then you clone a GUI?

If so, here's an answer I've come up with. This script assumes you have the Modulescript parented inside the localscript and is called config. I haven't tried it yet though:

local Players = game:GetService("Players")
local MarketPlaceService = game:GetService("MarketplaceService")
local localPlayer = Players.localplayer -- Make sure it's a localscript before using LocalPlayer
local playerGUI = localPlayer.PlayerGui

local gamepases = require(script.config) -- Change to wherever your ModuleScript is located.
local uiToClone = script.Frame:Clone() -- Change to wherever your UI is located.

local testProduct = gamepasses.testProduct

if testProduct.Active then
   uiToClone.Parent = playerGui -- Ensure you parent it to a ScreenGUI as otherwise it may not show.
   local gamepassId = testProduct.GamepassId
   -- Make sure that you modify the values below accordingly to your UI
   uiToClone.name.Text = testProduct.Name
   uiToClone.thumbnail.Image = testProduct.Image
   uiTOClone.price.Text = testProduct.Price

   uiToClone.thumbnail.MouseButton1Up:Connect(function()
      MarketPlaceService:PromptGamePassPurchase(localplayer, gamepassId) 
   end)
end

I hope this works, just tell me if it doesn't and I'd be happy to help!