Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you use TouchSwipe event on a Gui?

Asked by 7 years ago

I see that a GuiObject has a set of standard Touch Screen events, such as TouchLongPress, TouchSwipe, TouchPinch, etc.

However, I'm not sure these events are actually functional... At least in the way I am using them.

I put this code in a LocalScript that is the child of a Imageless ImageLabel:

script.Parent.TouchSwipe:connect(function()
    script.Parent.BackgroundColor3 = Color3.new(0,0,0)
    wait(1)
    script.Parent.BackgroundColor3 = Color3.new(255,255,255)
end)

This simply changes the color of the GUI to black and then white when I swipe the GUI to tell me that the event fired.

However, when I tested this on my mobile phone, I got no feedback, no color change, no event, no nothing. I believe I'm swiping correctly

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

maybe add a function

local function onSwipe(touchSwipe, touchCount)
    local trigger = false
    if touchSwipe == Enum.SwipeDirection.Left then
       trigger = true
    elseif touchSwipe == Enum.SwipeDirection.Right then
        --some code here if you like
        --also don’t write this if you need more than 1 directions, plus you can write up to 4 directions too
    end
    if trigger then
        script.Parent.BackgroundColor3 = Color3.new(0,0,0)
        wait(1)
        script.Parent.BackgroundColor3 = Color3.new(255,255,255)
    end
end

now we add the connect function now

script.Parent.TouchSwipe:connect(onSwipe)

Fun fact: the enum has a value from: 0 to 4 (4 is none) Use any of these directions if you like so

Enum.SwipeDirection.Left
Enum.SwipeDirection.Right
Enum.SwipeDirection.Up
Enum.SwipeDirection.Down

Tell me if it didn’t work. Oh plus it’s “:Connect()” not “:connect()” (<— if it helped, uhhh wait what)

Ad

Answer this question