Hello, I am new to working with xbox compatible games, and I have made a gui that opens and scrolls, but I can’t figure out how to activate the TextButton when you click the controller button, so I am just wondering how I would go about doing that?
I don’t really do xbox development (I don’t have a controller) but try something like this?
TextButton.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.ButtonA then
-- run code
end
end)
EDIT: Pretty sure RightTrigger activates MouseButton1Click
I don’t know too well about using TextButtons with an Xbox Controller, but here’s how I think it goes.
If you detect the player is using a controller, you should change it out to show which button does what action. So you could show “Back” with the B button icon.
This is after following the advice above, by the way! Just for a replacement of TextButtons and to help your players know what to do.
Thank you guys for helping me but I just realized what I can do, since I am making the TextButton.Selected true depending on what button it is on I can do something like this.
I have a table of the buttons by the way.
if (uis.KeyCode == Enum.KeyCode.ButtonA) then
for _,button in next, menuButtons do
if (button.Selected == true) then
-- rest of code here
end
end
end
Thank you again though for the help, I am only replying to this to let people know I figured it out and maybe someone else will find this useful.
If that’s the solution for this thread, you should be able to click a checkbox next to the Reply button on your message. That’ll set that as the solution and show in the original post.
Thank you, I am new to posting on here.
GuiService is intended to facilitate UI interactions with gamepads (Xbox controllers). I urge you to take a look through this and see what you can find; I myself have not used this before, so I can only point you to it.
Your current code seems like it could hit a number of edge cases and is not fully reliable. Any button that uses the Selected property could be triggered and produce finnicky or otherwise undesirable results. You can use UserInputService for gamepads of course, but you should use GuiService as a helper for UI interaction. For example, instead of checking for buttons with the selected property as enabled, use the SelectedObject reference property of GuiService.
That is gonna be a lot better to use, I still don’t understand it fully but I just have to mess around with it for awhile until I do, I am new to making something console compatible. also decided to make this the solution, so thank you for your help.
You can use one function and check if the button is being pressed or the GUI button is clicked.
local button = nil -- The button that will be clicked, replace this lol
local userInputService = game:GetService("UserInputService")
local function handler()
-- Handle it here.
end
userInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if(input.UserInputType == Enum.UserInputType.Gampad1) then
if(input.KeyCode == Enum.KeyCode.ButtonA) then
handler() -- Run the function
end
end
end)
button.MouseButton1Click:Connect(function()
handler() -- Run the function
end)
A controller doesn’t have a pointer like a computer mouse does, so this code wouldn’t necessarily work. The purpose of GuiService is to help you facilitate selection between Guis with your own system or by use of the engine’s automatic selection behaviour. You should also not be using MouseButton1 events for non-mouse inputs.