How can i make a shop with a Module Script

  1. What do you want to achieve?
    Hello, so i want to make a shop with a module script example in the module script :
    [“Test Item”] {
    price = 10
    }

And it adds automatically to the gui with a UILayout

  1. What is the issue?
    I can’t manage to do it

  2. What solutions have you tried so far?
    I tried myself and looked on forums

1 Like

Make a module as simple as that

local ShopItems = {
["Item1"] = { Name = "Sword", Price = 5},
["Item2"] = { Name = "Gun", Price = 10},
}

Inside the gui, loop through this table and create a frame/whatever and insert the data in e.g

for index, shopItem in pairs(ShopItems) do
    local newItem = template:Clone()
    newItem.ItemName.Text = shopItem.Name
    newItem.Price.Text = shopItem.Price
    
    newItem.Visible = true
    newItem.Parent = itemScrollingFrame
end
1 Like

Thank you, and how can i do with the buy button ? (Im sorry im new to modules scripts)

That’s fine dw,
Inside the template frame, you could also add the buy button inside

for index, shopItem in pairs(ShopItems) do
    local newItem = template:Clone()
    newItem.ItemName.Text = shopItem.Name
    newItem.Price.Text = shopItem.Price
    
    newItem.BuyButton.MouseButton1Down:Connect(function()
           ShopEvent:FireServer("BuyItem", shopItem.Name)  
    end)

    newItem.Visible = true
    newItem.Parent = itemScrollingFrame
end
1 Like

Okay, thank you for answering ! It helped my alot!

1 Like

No problem, good luck! :slight_smile: [limit]

1 Like

What do you do if you have a leaderstats on a diffrent script and want to make a purchase/shopHandler on a diffrent script. How could you get gold?