Im trying to create an alphabetic sorter which I can’t do manually since I have hundreds of stuff to sort so I tried to automate its but Idk how to change the position of a GUI Please help I tried searching online and I found nothing. %IN GAME%
Well, assuming you aren’t using scale,
script.Parent.Position -= Udim2.new(0,0,0,5)
Use a UIListLayout or UIGridLayout. You can have it sort in the property. GUI doesn’t use Vector3, it uses UDim2.new(Xscale,Xoffset,Yscale,Yoffset)
Gui’s use UDim2, not position. So, you would have to use UDim2new()
.
I need to do its in-game, like this
Here’s what I can think of. In your LocalScript, make it that when the player clicks and the button and if they picked Sort by ABC, then create an instance of UIListLayout and put it in the frame or scrollingframe where the list will show up. Here’s an example:
There’s a debounce so they don’t spam click. Also if there’s already a UIListLayout, don’t create another one. If they choose something else, have the UIListLayout destroyed so it won’t affect how the others are sorted. In my scripting example, it uses a TextBox to test, but you can change that to how your game uses.
local scrollingframe = script.Parent.Parent:WaitForChild("ScrollingFrame")
local chosen = scrollingframe.Parent:WaitForChild("TextBox")
local db = true
script.Parent.MouseButton1Click:Connect(function()
if db == true then db = false
if chosen.Text == "SortByABC" then
if scrollingframe:FindFirstChild("UIListLayout") == nil then
local sortabc = Instance.new("UIListLayout")
sortabc.SortOrder = Enum.SortOrder.Name
sortabc.Parent = scrollingframe
else
end
elseif chosen.Text ~= "SortByABC" then
if scrollingframe:FindFirstChild("UIListLayout") ~= nil then
scrollingframe:FindFirstChild("UIListLayout"):Destroy()
end
end
task.wait(1)
db = true
end
end)
thank you for your response but because of how my code is built would prob have created like 5 new porblems
but do you know anyway to add to the position of the y value of a GUI?
Use a list layout, you can simply just change the way it sorts to the original when they remove the filter. It would be about 20 times more efficient then the way you are trying to do it. @anon96575334 is right. I can help if you need it.
Yes, just insert a UIListLayout then use the script to change the SortOrder how it fits what the player choose. If you name your button or label by their name, then that’s what the SortOrder reads. You don’t have to use the script above that adds and destroys it, just keep the UIListLayout in the frame where the items show up and use a script to change how it is layout.
You can change the sortorder like this to what it seems fit:
PathToUIListLayout.SortOrder = Enum.SortOrder.Name
PathToUIListLayout.SortOrder = Enum.SortOrder.LayoutOrder
SortOrder.LayoutOrder is the default and you can use your script to customize it when you are not sorting by name or alphabetically.
The UIListLayout also have a Padding property, scale,offet, so you can set how much space between each item in the frame. The UIListLayout will automatic put them in position.
gui.Position = UDim2.new(xScale,xOffset,yScale,yOffset)
yScale and yOffset are the yPositions. yScale stays in relation to the frame or gui it is a child of. yOffset can go out of position if the screen of the game changes.
I use a UIListLayout for my Global Leaderboard and it sorts the player by their rank # so I don’t have to worry about positioning because the UIListLayout will position them.
There is also a UIGridLayout with a sortorder, too. Try them both.