Recently, I implemented a cursor to navigate menus with for controllers/gamepads. The problem with this is since I can’t directly fire MouseButton1Click on buttons, I must set the object that the cursor is hovering over to the SelectedObject, which forces the player to have to press A twice (once to select the object, and another to click on the object) to click on buttons in the menu.
Example of the problem:
So, is there a way to fire the MouseButton1Click event or somehow access the function connected to MouseButton1Click?
I would recommend checking if the button has the “Selected” property to true then using UserInputService, check if the player has used ButtonA. Example:
local PressedOnce = false
local PressedTwice = false
UIS.InputBegan:Connect(function(inpt, gpe)
if gpe then
return
end
if inpt.KeyCode == Enum.KeyCode.ButtonA then
if PressedOnce == true then
-- // open function here
PressedTwice = true
PressedOnce = false
return
end
PressedOnce = true
spawn(function()
if not PressedTwice then PressedOnce = false end
end)
end
end)
I don’t think so, but what you could do is create your own function and call it with parameters for the specific UI for MouseButton1Down and GamepadInput
On Console, all UI is selectable to my knowledge, as this is how most people are able to use buttons, pressing the back button to select then pressing A to confirm.
I usually keep all my button functions in a module anyway so I can access them easily, I recommend doing this because then you can keep your code tidy.
Alright, but what would I do for buttons that use the same function? Create a separate, hard coded function for each of them? (Example: the HOME and CUSTOMIZE tabs in the gif in the OP)
Ah, easy. Just check if an argument was added for the button.
v.MouseButton1Click:Connect(function()
module.Function1(v)
end)
-- // in module
module.Function1 = function(button)
if button then
-- // will print if the button argument was given
end
end