Mobile/ipad Multitouch scripting examples or tutorials

Does anyone have any examples of scripts that utilize multitouch on mobile devices? For example, if you had a screengui that required a player to press and hold a button, and also simultaneously interact with the screen with another touch input. From what I’ve seen this will cause the first ‘press and hold’ to release with any new touch event.

Searching the forum for multitouch comes up with little to no results.

Nothing, nobody? Not a bite? Anybody write gui’s for mobile? no?

Late response, but this may be useful for anyone with a similar issue.

The structure of the documentation makes it difficult to find, but we can read in UserInputService | Roblox Creator Documentation that a unique touch will always use the same InputObject instance for all of its events. (This is also true for all other inputs, as noted on the InputObject page.)

This means if you get a touch input, you can store a reference to its InputObject, and when handling later inputs can compare your stored InputObjects with those later InputObjects to see if it is the same touch.

For example:

local firstTouch

userInputService.TouchStarted:Connect(function(inputObject)
   if (not firstTouch) or (firstTouch == inputObject) then
      firstTouch = inputObject
      print("First touch started")
   else
      print("A different touch started")
   end
end)

userInputService.TouchEnded:Connect(function(inputObject)
   if firstTouch == inputObject then
      print("First touch ended")
      firstTouch = nil
   else
      print("A different touch ended")
   end
end)
6 Likes

Can you use task.spawn to enable multiple touch inputs to be recieved or no? Because i have a sprint button which uses a touchlongpress and I need it to be able to be activated while walking

If you’re trying to track multiple touches you can just do that, no need for task.spawn:

local TrackedTouches = {}

UserInputService.TouchStarted:Connect(function(InputObject)
   TrackedTouches[#TrackedTouches+1] = InputObject
   print("A touch started!")
end)

UserInputService.TouchEnded:Connect(function(InputObject)
   local Index = table.find(TrackedTouches, InputObject)
   if Index then
      table.remove(TrackedTouches, Index)
      print("A touch ended!")
   end
end)

If you want to detect something after a delay (e.g. implement your own custom TouchLongPress), you can do that using task.spawn/task.wait/task.delay. Here I use task.wait:

UserInputService.TouchStarted:Connect(function(InputObject)
   print("A touch started!")
   task.wait(3)
   if InputObject.State ~= Enum.UserInputState.Begin and
      InputObject.State ~= Enum.UserInputState.Change
   then
      print("A touch was held for some time!")
   end
end)

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