You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
Alright, so whenever you have a game, especially a title screen, you want to be able to detect when a player presses a button, taps the screen, or presses a button on their gamepad.
What is the issue? Include screenshots / videos if possible!
But in doing so, you would have to make 3 UserInputService functions for it to work.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried maybe looping through a table and trying to get every UserInputType.
local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(Input, gameProcessedEvent)
-- Do the computer thing
end)
UserInputService.InputBegan:Connect(function(Input, gameProcessedEvent)
-- Do the mobile thing
end)
UserInputService.InputBegan:Connect(function(Input, gameProcessedEvent)
-- Do the gamepad thing
end)
local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(Input, gameProcessedEvent)
if gameProcessedEvent then return end -- Ensure the event wasn't processed
if Input.UserInputType == Enum.UserInputType.Keyboard then
-- Do the computer thing
elseif Input.UserInputType == Enum.UserInputType.Touch then
-- Do the mobile thing
elseif Input.UserInputType == Enum.UserInputType.Gamepad1 then
-- Do the gamepad thing
end
end)
--Callback for a bound action
--You can have one for every bound action or create a unique callback for every single one
local function handleAction(actionName, inputState, inputObject)
if actionName == "TestAction" then
if inputState == Enum.UserInputState.Begin then
--Do something if the player begins pressing a button
end
end
end
--You can pass as many keys to the :BindAction() function as you want. Each key will trigger the callback
--You can also automatically create buttons for mobile players by setting the third parameter to true
--The name of the action can be whatever you want, it can be used to unbind an action later
ContextActionService:BindAction("TestAction", handleAction, true, Enum.KeyCode.H, Enum.KeyCode.ButtonY)
--For example like this:
ContextActionService:UnbindAction("TestAction")