How to detect touch ended on the screen for each finger

I would like to know how to detect touch ended on the screen for each finger.
This code was not working so let me know how to achieve the intended result of this code!

UserInputService.TouchStarted:Connect(function(input)
	print(input.Position)
	while input do
		wait()
		print("input exist")
	end
end)

Based off what I see, you seem to be using .TouchStarted instead of .TouchEnded as you say that you want to know when the touch ended. If the issue is something else let me know.

4 Likes

Interesting that u have a while loop and a normal wait. The while loop is redundent, roblox firesevents with everything. So given that its an event in a while loop, so everytime an event does occur, that loop will x2 and keep going.

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(Input, GameProcessedEvent)
	
	if GameProcessedEvent then return end
	
	print(Input.KeyCode.Name)
	
end)```

And then this one is for mobile,

I see u are using touchstarted however, you have input only, change that to:


UserInputService.TouchStarted:Connect(function(input, gameprocessed)

The reason for that I am sure u do know, but if you didnt, its to detect if the player is typing a message or not.

So the actual code to this is as follows: (It could be better)

local UserInputService = game:GetService("UserInputService")

local activeTouches = {}

UserInputService.TouchStarted:Connect(function(touch, processed)
	if not processed then
		activeTouches[touch] = touch.Position
		print("Finger DOWN:", touch, "Position:", touch.Position)
	end
end)

UserInputService.TouchMoved:Connect(function(touch, processed)
	if activeTouches[touch] then
		activeTouches[touch] = touch.Position
		print("Finger MOVE:", touch, "Position:", touch.Position)
	end
end)

UserInputService.TouchEnded:Connect(function(touch, processed)
	if activeTouches[touch] then
		print("Finger UP:", touch, "Last Position:", touch.Position)
		activeTouches[touch] = nil
	end
end)```

I hope this helped you out. :slightly_smiling_face:
2 Likes

That’s what I wanted to do.
Thank you so much <3<3<3

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.