I am currently reworking my menu code and how it works, but I have ran into a problem. When you change pages on a gamepad, it should automatically select the button with the smallest SelectionOrder, but it doesn’t. Here’s the code that will select it:
function Package.SelectLowestOrder(page: Frame)
for index, value in page:GetChildren() do
if value:IsA("GuiObject") and value.SelectionOrder == 1 then
GuiService.SelectedObject = value
end
end
end
Code that changes pages:
if values[2] or values[4] then
PageToAdvanceTo.Visible = true
PageToAdvanceTo:SetAttribute("Enabled", true)
PageToAdvanceTo.Position = PreTweenUDims.In
PageToAdvanceTo:TweenPosition(TweenUDims.In, Enum.EasingDirection.In, Enum.EasingStyle.Quad, TweenTime)
if selectEnabled and UserInputService.GamepadEnabled then
Package.SelectLowestOrder(PageToAdvanceTo)
end
task.wait(TweenTime)
end
I don’t know why that is happening because I can’t seem to recreate it for some reason. It’s selecting the GUI object for me. Have you tried restarting Roblox Studio?
local GuiService = game:GetService('GuiService')
selectEnabled = true
TweenTime = 1
function SelectLowestOrder(page: Frame)
for index, value in page:GetChildren() do
if value:IsA("GuiObject") and value.SelectionOrder == 1 then
GuiService.SelectedObject = value
end
end
end
if true then -- values[2] and values[4]
local PageToAdvanceTo = game.Players.LocalPlayer.PlayerGui:WaitForChild('ScreenGui').Frame
PageToAdvanceTo.Visible = true
PageToAdvanceTo:SetAttribute("Enabled", true)
PageToAdvanceTo.Position = UDim2.fromScale(0, 0) -- PreTweenUDims.In
PageToAdvanceTo:TweenPosition(UDim2.fromScale(0.5, 0.5), Enum.EasingDirection.In, Enum.EasingStyle.Quad, TweenTime)
if selectEnabled and true then -- UserInputService.GamepadEnabled
SelectLowestOrder(PageToAdvanceTo)
end
task.wait(TweenTime)
end
Edit: I also tried putting the function into a ModuleScript but it still selects it for me.
My assumption is that the GuiObject also needs to be Active, and Selectable for it to be valid. If it’s just a frame, it might not be valid either? I tried to make console support once, but it was almost the last thing I tried in this life. It sucked.