Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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.

3 comments

1

only use if not gameProcessedEvent then

0

Thanks!

0

yHasteeD this works though

This discussion is preserved as it was. New answers, comments, and votes are closed.