Well in this case, there's an easy enough solution to not be bothered with ROBLOX's libraries. If you're completely sure that each button will be the exact same size, you could simply set the ScrollingFrame's CanvasSize Y Offset to the product of #Buttons * Button.Size.Y.Offset. Here could be an example of how to do this:
Note
This script only implements the concept of creating an auto scroll manager, but should be easy to figure out how to add it to a player list script.
local Buttons = {}
local Scroll = script.Parent:WaitForChild("ScrollingFrame")
local function NewButton()
local Button = Instance.new("TextButton",Scroll)
Button.Size = UDim2.new(1,0,0,25)
Button.Position = UDim2.new(0,0,0,#Buttons*Button.Size.Y.Offset)
return Button
end
while wait(1) do
local Button = NewButton()
if Button.Position.Y.Offset+Button.Size.Y.Offset > Scroll.AbsoluteSize.Y then
Scroll.CanvasSize = UDim2.new(0,0,0,#Buttons*Button.Size.Y.Offset+Button.Size.Y.Offset)
else
Scroll.CanvasSize = UDim2.new(0,0,0,0)
end
Buttons[#Buttons+1] = Button
end
If you wanna see what this'd look like without testing it raw, you can look here: https://gyazo.com/874d0baa0a0f34fb819a2ece8c0c12bc
What's actually happening
In case the solution was obfuscated in all that text, this is basically the auto scroll part:
local SizeYOffset = v.Size.Y.Offset
if v.Position.Y.Offset+SizeYOffset > Scroll.AbsoluteSize.Y then
Scroll.CanvasSize = UDim2.new(0,0,0,#Buttons*SizeYOffset+SizeYOffset)
end
So we're basically getting the bottom position of the GUI by adding it's size Y to it's actual position Y, and comparing it to the size Y of the ScrollingFrame, to see if it exceeds the limit. And if it does, we'll make the CanvasSize's Y Offset be equal to the equation above (Amount of buttons mulitplied by the static size Y of each button, plus the size Y of the button).
Auto-positioning the scroller
If you want to make something that automatically positions the scroll bar to the end of the list, you would set it's Y vector to the CanvasSize Y Offset, subtracted by the ScrollingFrame's AbsoluteSize Y like this:
Scroll.CanvasPosition = Vector2.new(0,Scroll.CanvasSize.Y.Offset-Scroll.AbsoluteSize.Y)
Here's how this would look: https://gyazo.com/595c4f2fe1658b88e3eaf2c7b5a70cb3
Additional information
There are a lot of ways to create a automatic scrolling frame, all in which depend on how you want it to function (i.e, pushing all messages up, pushing all messages down, adding different size labels, ect). However, this is probably the most practical method for creating an auto scroll for something like this, since all text buttons will have the same Size Y Offset, and typically all player lists add a new player at the bottom of the list.
Hope that helped. If you have any questions, just let me know.
2 comments
this is a great explanation especially since it introduces control arrays which lua doesn't have
Thanks, that's just what I was looking for. Appreciate it!