The TouchLongPress event fires after a brief moment when the player holds their finger on the UI element using a touch-enabled device. It fires with a table of
DataType/Vector2 that describe the relative screen positions of the fingers involved in the gesture. In addition, it fires multiple times with multiple
Enum/UserInputStates: Begin after a brief delay, Change if the player moves their finger during the gesture and finally with End. The delay is platform dependent; in Studio it is a little longer than one second.
Since this event only requires one finger, this event can be simulated in Studio using the emulator and a mouse.
Below is an example of TouchLongPress firing on a Frame that is
GuiObject/Active. Below, the event fires after a brief delay (Begin) and then continually as as the finger is moved (Change). It fires one last time after it is released (End).
UserInputService/TouchLongPress, an event with the same functionality but is not restricted to a specific
An array of
Move UI Element with TouchLongPress
This code sample allows the player to manipulate the screen position of some UI element, like a
Frame, by holding down on the UI element for a brief moment. Then, the player moves their finger and releases. During the gesture the Frame is colored blue with a white outline.
local frame = script.Parent frame.Active = true local dragging = false local basePosition local startTouchPosition local borderColor3 local backgroundColor3 local function onTouchLongPress(touchPositions, state) if state == Enum.UserInputState.Begin and not dragging then -- Start a drag dragging = true basePosition = frame.Position startTouchPosition = touchPositions -- Color the frame to indicate the drag is happening borderColor3 = frame.BorderColor3 backgroundColor3 = frame.BackgroundColor3 frame.BorderColor3 = Color3.new(1, 1, 1) -- White frame.BackgroundColor3 = Color3.new(0, 0, 1) -- Blue elseif state == Enum.UserInputState.Change then local touchPosition = touchPositions local deltaPosition = UDim2.new( 0, touchPosition.X - startTouchPosition.X, 0, touchPosition.Y - startTouchPosition.Y ) frame.Position = basePosition + deltaPosition elseif state == Enum.UserInputState.End and dragging then -- Stop the drag dragging = false frame.BorderColor3 = borderColor3 frame.BackgroundColor3 = backgroundColor3 end end frame.TouchLongPress:Connect(onTouchLongPress)