Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I detect if a player clicks/taps the screen without clicking/tapping any GUI?

Asked by
Vik954 48
5 years ago

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.

1 answer

Log in to vote
0
Answered by 5 years ago

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.

1
only use if not gameProcessedEvent then yHasteeD 1819 — 5y
0
Thanks! Vik954 48 — 5y
0
yHasteeD this works though despicablejack2005 83 — 5y
Ad

Answer this question