I am working on a game based on sports, with some sports which are practiced by two teams, and I need a screen click/tap event. Since I made a custom chat GUI I need an event which detects if a player clicks/taps the screen on the screen and without clicking/taping any GUIs.
In a local script inside of StarterPlayerScripts, I put:
01 | local userinputservice = game:GetService( "UserInputService" ) |
02 |
03 | userinputservice.InputBegan:Connect( function (input, gameProcessedEvent) |
04 | local inputType = input.UserInputType |
05 | if inputType = = Enum.UserInputType.MouseButton 1 then -- When a player clicks the screen |
06 | if gameProcessedEvent = = true then -- If the player pressed a button. |
07 |
08 | else |
09 | -- Put your code here |
10 | end |
11 | end |
12 | end ) |
This will run your code where it says "Put your code here" if the player presses a screen. It won't run when a button is pressed but will work if you press a TextLabel.