Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

ScrollingFrame (List GUI) not scaling properly?

I'm using a ScrollingFrame and adding a TextLabel for each item in a list-fashion. However, the bigger the list, the bigger the text becomes, and, instead of fitting all items to the ScrollingFrame's Canvas, they are cut off after the 20th item.

Summarized code below:

k = 0
for i,v in pairs(items) do
	scrollingFrame.CanvasSize = UDim2.new(1,0,k*.05,0)
	local itemLabel = Instance.new("TextLabel", scrollingFrame)
	itemLabel.Size = UDim2.new(1,0,.05,0)
	itemLabel.Position = UDim2.new(0,0,(scrollingFrame.CanvasSize.Y.Scale/.05)*k,0)
	itemLabel.Text = "Item #" .. i
	itemLabel.TextScaled = true
	k = k + 1
end

Practical example: https://i.gyazo.com/7a8f6e3b9310bda8195568d8fcfbbe9e.gif (note there are 50+ commands)

Thank you in advance.

1 answer

✓ Accepted answer

The reason the text is getting bigger the longer the list goes is due to you using the Scale property in the position. Try using Offset for the items, but you can still use Scale for the actual frame's size.

Also, you shouldn't manually position the buttons as there is a new way to do so with ROBLOX's new UIListLayout. You can configure padding, sizes of objects, and you don't need to manually position them, simply parent them into the ScrollingFrame.

After adding a UIListLayout, use this code to fix your problem:

for i,v in pairs(items) do
    scrollingFrame.CanvasSize = UDim2.new(1,0,0,20) -- Edit the offset Y to however big you make the objects
    local itemLabel = Instance.new("TextLabel", scrollingFrame)
    -- UIListLayout takes care of the positioning and sizing for you, no need to do it here.
    itemLabel.Text = "Item #" .. i
    itemLabel.TextScaled = true
end

If I helped, upvote and accept my answer! :)

2 comments

0

I've never used this before, so this may be something really simple - but everything is very big and clustered now - http://prntscr.com/f2ttxf . Any idea on how to fix?

0

Try editing the padding

This discussion is preserved as it was. New answers, comments, and votes are closed.