Detect if player has clicked/tapped their screen

Really quick question. How can I detect if a player has clicked or tapped on their screen without using a tool or UI?

1 Like

for the mouse UserInputService.InputBegan and touch screens UserInputService.TouchStarted

Both articles have code samples, InputBegan will need to check against Enum.UserInputType.MouseButton1.

1 Like

Oh dang. I forgot UserInputService existed…

1 Like

Try this:

--//Services
local UserInputService = game:GetService("UserInputService")

--//Functions
UserInputService.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Touch or input.UserInputType == Enum.UserInputType.MouseButton1 then
		print("Clicked/tapped screen")
	end
end)
4 Likes