Shop spots help

Normally, in the shops, the creators only put one spot and with a script the gui gets filled with the items on sell, how do I achieve this?

Sorry by the vague post, I’m at phone and I can’t screenshot here, I can send you images later, I hope you respond me and thanks :+1:

Here is a four part series from Alvin Blox. It may, or may not, address what you are asking.

If I understand what you’re asking for correctly, you want a shop GUI to load all of the items you want in your shop? Like, you have a folder with all of the tools you can buy, and want to automatically load them into a shop GUI.

One way to go about this is to make a prefab item slot, with information like an image, price, description, and a buy button. We can store this prefab in the script. To make sure the GUI will fill out properly and be scalable if you add more items, make the GUI a ScrollingFrame, with a UIGridLayout. You can edit the settings of the grid layout until it looks right with multiple shop items.

Along with this, you could save the information about the tool using value instances within the tool.
StringValue Description
IntValue Price
IntValue ImageId

Then, using a for loop that would looks something like this:

local ShopItems = -- Folder with tools

local PrefabItem = script.PrefabItem

local Frame = -- scrolling frame where the items will go

for _, Tool in pairs(ShopItems:GetChildren()) do
    local Item = PrefabItem:Clone()
    Item.Name = Tool.Name

    -- Assuming the prefab contains a TextLabel "Description", TextLabel "Price", ImageLabel "Picture", TextButton "Buy"
    Item.Description.Text = Tool.Description.Value
    Item.Price.Text = Tool.Price.Value
    Item.Picture.Image = "rbxassetid://" .. Tool.ImageId.Value

        -- however you go about buying the tool

    Item.Parent = Frame

Now, since we used a grid layout, it will automatically position them into place for us!

Ok so i saw this:

for _, Tool in pairs(ShopItems:GetChildren()) do
local Item = PrefabItem:Clone() 
Item.Name = Tool.Name

Those lines will identify how many items are in that carpet and duplicate them with the amount of childrens?

Also, i can see that they will duplicate only, but how do i save a position for a spot? For e.g.

There first spot is already on use, so when a spot duplicates, will find if there’s already a spot, and will select a position right at the spot.

If the first line is completed then it’s position will be in the second line.

The for loop will get every item that is in the folder. If you use a UIGridLayout, like I explained in the beginning, it will automatically fill out the positions for the items, so you don’t have to worry about scripting that part in.

1 Like