Prevent UI Elements in a scrolling frame from stacking

I’m making an admin control GUI for my game, and I have a scrolling frame that TextButtons go in so I can “select” a user.

I can create the buttons, but I can’t position them correctly. Currently, they just stack up but don’t spread out. Could someone try explaining how to fix this?

I’ve tried doing this

local function AddPlayerToSelect(plr: Player)
	local button = Instance.new("TextButton")
	button.Text = plr.Name .. "\n(@".. plr.DisplayName..")"
	button.Size = UDim2.new(0, 87,0, 31)
	button.TextScaled = true
	button.TextColor3 = Color3.fromRGB(255, 255, 255)
	button.Parent = PlayerSelect
	button.BackgroundTransparency = 1
	local Y
	for i, child in PlayerSelect:GetChildren() do
		Y = UDim.new(0, child.Position.Y + 10)
	end
	button.Position.Y = Y
end

for i, plr in Players:GetPlayers() do
	AddPlayerToSelect(plr)
end

Players.PlayerAdded:Connect(function(plr)
	AddPlayerToSelect(plr)
end)

Have you considered just using something like a UIListLayout to do it automatically? You won’t have to fight the strange arithmethic UI manipulation poses

1 Like

Nope. I thought that it would’ve needed weird math. I’ll try that, thanks!

Just add padding (which is under the properties of UIListLayout) and it should separate out your buttons, you can also fiddle with the other properties to get the layout you want.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.