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:
local userinputservice = game:GetService("UserInputService") userinputservice.InputBegan:Connect(function(input, gameProcessedEvent) local inputType = input.UserInputType if inputType == Enum.UserInputType.MouseButton1 then -- When a player clicks the screen if gameProcessedEvent == true then -- If the player pressed a button. else -- Put your code here end end 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.