How would I go about displaying an inventory?

Hey developers.
I am trying to make an inventory GUI using an array of item IDs that a player owns.

For example, if the array was {1,4,8} then a player would own the trails with the IDs 1, 4 and 8.

I then get the trail name by using trails[ID].Trail.Name.

On equips, I send a remote event to a server script that checks if the player owns the trail, removes any current trail and equips the new one.

My only issue is… I have no idea how to display the trails in an inventory format. Does anyone know how I would do this given the information above?

Thanks heaps,
Winky. :revolving_hearts:

First you can make multiple GUI “item frames”, each representing a item from the table. Then just insert these into a UIListLayout with properties of your choice.
Here is a basic example:

UIListLayout = game.StarterGui.GUI.UIListLayout
ItemsOwnedArray = {1,4,8}
for x = 1,#ItemsOwnedArray,1 do --loop through owned items table
    Name = trails[ItemsOwnedArrary[x]].Trail.Name

ItemTextLabel = Instance.new("TextLable") --create a textlabel that represents the item in your inventory GUI (you can use a frame containing whatever you want. I'm just using a textlabel as an example)
ItemTextLabel.Text = Name
ItemTextLabel.Parent = UIListLayout --let your UIListLayout do the work
end

This is just an example, but it shows the basics of how you would want to display your inventory.

Good luck!

https://developer.roblox.com/en-us/api-reference/class/UIListLayout

1 Like

I considered using a UIListLayout, but I was hoping for a grid that has 3 trails going across and 4 going downwards (for example).

Should I parent frames to the UIListLayout or the the parent of the UIListLayout?

There is also a UIGridLayout if you do want that grid-like layout you had mentioned

1 Like

Parent the frames inside the UIListLayout. The UIListLayout object only manipulates it’s children. If you wanted a to do as you mentioned, you can use UIListLayout’s cousin UIGridLayout instead.

https://developer.roblox.com/en-us/api-reference/class/UIGridLayout