UserInputService difference between Touch and Click

Hey. I have the test code below. It’s working totally fine when i touched down and swipe my finger on screen. It’s printing location. But with the mouse it’s not working. What am i missing in here? Of course i can do this with different methods but i would like to learn the logic.

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if input.UserInputType == Enum.UserInputType.Touch or input.UserInputType == Enum.UserInputType.MouseButton1 then		
		input:GetPropertyChangedSignal("Position"):Connect(function()
			print(input.Position)
		end)
	end
end)
1 Like

You’re trying to prrint a button,
MouseButton1 is the left click on your mouse

Oh it’s make sense. Touch has a different properties but not MouseButton1. Do you have any idea to get mouse position too when clicked ? I want to do both check in single operation.

local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if input.UserInputType == Enum.UserInputType.Touch or input.UserInputType == Enum.UserInputType.MouseMovement then		
		input:GetPropertyChangedSignal("Position"):Connect(function()
			print(input.Position)
		end)
	end
end)

I replaced MouseButton1 with MouseMovement

I tried it before you reply it’s seems to be working but it’s not a good way to do it i guess. There is more problems to fix lol. Thank you soo much for your help!

1 Like