The TouchSwipe event fires when a user swipes their fingers on a
This event can be used to determine when a user swipes their fingers on the screen of their device and the direction that the user swiped.
For more precise tracking of touch input movement, use using
To check if a user’s device is TouchEnabled, and that touch events will fire, see
This event only fires when the Roblox client window is in focus. For example, inputs will not be captured when the window is minimized.
As this event only fires locally, it can only be used in a
An `Enum/SwipeDirection, indicating the direction the user swiped
Number of touches (e.g. fingers) involved in the gesture
Indicates whether the game engine internally observed this input and acted on it. Generally this refers to UI processing, so if a button was touched or clicked from this input,
Touch Swipe a GUI
The example below demonstrates the
UserInputService/TouchSwipe|TouchSwipe event by
GuiObject|GUI element’s position 100 pixels in the direction of the swipe according to the value of the
In order for this example to work as expected, it must be placed in a
LocalScript that is parented to the gui being swiped.
local UserInputService = game:GetService("UserInputService") local gui = script.Parent local swipePositionY = gui.Position.Y.Offset local swipePositionX = gui.Position.X.Offset local camera = game.Workspace.CurrentCamera local maxY = camera.ViewportSize.Y - gui.Size.Y.Offset local maxX = camera.ViewportSize.X- gui.Size.X.Offset local function TouchSwipe(swipeDirection, numberOfTouches, gameProcessedEvent) if swipeDirection == Enum.SwipeDirection.Up then swipePositionY = math.max(swipePositionY-200, 0) elseif swipeDirection == Enum.SwipeDirection.Down then swipePositionY = math.min(swipePositionY+200, maxY) elseif swipeDirection == Enum.SwipeDirection.Left then swipePositionX = math.max(swipePositionX-200, 0) elseif swipeDirection == Enum.SwipeDirection.Right then swipePositionX = math.min(swipePositionX+200, maxX) end gui:TweenPosition(UDim2.new(0, swipePositionX, 0, swipePositionY), "Out", "Quad", .25, true) end UserInputService.TouchSwipe:Connect(TouchSwipe)