I want to make my own scrolling frame because 1st, I want all the buttons to start from the center and to the right; 2nd, I want to only go scroll one button forward for every scroll input
I have mostly done this ^^ but the UI is clipping on the left of the screen.
video:
robloxapp-20231120-0855292.wmv (1.7 MB)
picture:
I don’t know what’s going on cause I don’t work with UI much
--loading the levels onto the frame
function guiModule.loadLevels()
local player = Players.LocalPlayer
local screenGui = player.PlayerGui:WaitForChild("ScreenGui")
--CLEAN UP
for i, v in pairs(screenGui.LevelSelectPage.LevelsFrame:GetChildren()) do
if v:IsA("Frame") and v.Visible == true then
v:Destroy()
end
end
for i, v in pairs(Levels) do
local frame = screenGui.LevelSelectPage.LevelsFrame.LevelTemplate:Clone()
frame.Parent = screenGui.LevelSelectPage.LevelsFrame
frame.Position = UDim2.new( ((i-1)*.3)+(0.5-frame.Size.X.Scale/2) ,0,0,0)
frame.NameButton.Text = v.Name
frame.Name = v.Name
frame.Visible = true
end
end
--ON SCROLL
local function ScrollAction(inputObj)
if not hoveringToScroll then print(hoveringToScroll) return end
local children = screenGui.LevelSelectPage.LevelsFrame:GetChildren()
for i, v in pairs(children) do if v.Name == "LevelTemplate" then table.remove(children, i) end end
local selectedIndex = guiModule.getLevelIndex(levelSelected)
if inputObj.Position.Z == 1 and selectedIndex ~= #Levels then
selectedIndex += 1
elseif inputObj.Position.Z ~= 1 and selectedIndex ~= 1 then
selectedIndex -= 1
end
levelSelected = Levels[selectedIndex].Name
for i, v in pairs(children) do
local middle = (0.5-v.Size.X.Scale/2)
local index = guiModule.getLevelIndex(v.Name)
TS:Create(v, scrollInfo, {Position = UDim2.new(middle+.3*(index-selectedIndex),0,0,0)}):Play()
end
print(levelSelected, selectedIndex)
end
--get level index
function guiModule.getLevelIndex(name)
for i, v in pairs(Levels) do
if v.Name == name then
return i
end
end
end
--the levels
local Levels = {
{
["Name"] = "Cadiz",
["Prerequisite"] = false,
},
{
["Name"] = "Granada",
["Prerequisite"] = false,
},
{
["Name"] = "Albacete",
["Prerequisite"] = false,
},
---and more(its too long)
}
sorry if I’m just dumping code on yall but please help me