So I am making a system for equipping weapons and I need help making the inventory system. I want to be able to put all of the player’s weapons inside the scrolling frame with text labels but I have no idea how to do that. I need to make sure that all of the player’s weapons are inside and you can scroll if the list is bigger. I have only figured out how to get the player’s weapons as instances inside an array. Any ideas on how I can achieve this?
You can just iterate through the table and create a new text label containing all of the information. Then change the ScrollingFrame’s CanvasSize to be the size of the UIListLayout’s AbsoluteContentSize
local scrollingFrame = game:GetService('Players').LocalPlayer.PlayerGui.ScreenGui.ScrollingFrame
local uiListLayout = scrollingFrame.UIListLayout
local inventory = game:GetService('Players').LocalPlayer.Inventory
for i,v in pairs(inventory:GetChildren()) do
local textLabel = Instance.new('TextLabel')
textLabel.Size = UDim2.new(1,0,1,0)
local uiAspectRatioConstraint = Instance.new('UIAspectRatioConstraint')
uiAspectRatioConstraint.AspectRatio = 5
uiAspectRatioConstraint.Parent = textLabel
textLabel.Text = v.Name
end
scrollingFrame.CanvasSize = UDim2.new(0,uiListLayout.AbsoluteContentSize.X, 0, uiListLayout.AbsoluteContentSize.Y)
I just tried to do that but it just inserts the textlabels with one of them being as big as the canvas.
Oh my bad, parent the UIAspectRatio to the text label
Oh I see, try using a UIGridLayout instead.
Oh there is a UIGridLayout? Now I feel like I haven’t explored roblox studio to its most
Yeah, there are a bunch of UI features in studio, search “UI” when you go to create an instance and they should all appear.
Thanks a lot! I will check it out.
Just wanted to add that you should probably use AutomaticCanvasSize for UIGridLayouts. Using AutomaticCanvasSize with UIListLayouts is frankly unbearable and super inconsistent because the sizes of the elements can vary whereas with a UIGridLayout, it is consistent among every element.