Hey, so I made a double tap to sprint for my computer users and it works great, so I had to make one for my mobile users as well.
I didnt see anything on devforum about it, so if anyone out there was wondering how to do this on mobile then your in the right place.
local firstTap = false
local runningWindow = false
local firstTapThreshold = .4
local runningwindowThreshold = 1
UIS.TouchTap:Connect(function(touchPositions, gameProcessedEvent)
if gameProcessedEvent then return end
if not firstTap then
firstTap = true
print("First tap!")
task.spawn(function() --[[
We create a new thread and wait a tiny bit of time then reset firstTap
basically its the "window of time" the player gets
--]]
task.wait(firstTapThreshold)
if firstTap then
firstTap = false
print("Did not tap into time!")
--[[ We check if firstTap is still true and if it is then reset it because
the player didnt tap within our firstTapThreshold
--]]
end
end)
else
runningWindow = true
task.spawn(function()--[[
We create another thread when we have successfully tapped within firstTapThreshold
Basically the point of this is if you want to run any other code after the runningWindowThreshold
Ex.
Mobile players cant move and press the screen at the same time, so this window of time gives you a bit
of leg room to run some code when the runningWindow is closed i.e false
Let's say that when you stop moving you want to also stop the animation playing,
Just check when the MoveDirection Magnitude is = 0 and check if they are running and the
runningWindowThreshold has closed, so players have some time before we stop their sprinting
]]
task.wait(runningwindowThreshold)
runningWindow = false
print("The run window closed")
end)
print("This is the 2nd tap")
-- Change walkspeed or whatever you wanna do
end
end)
UIS.TouchEnded:Connect(function(touch, gameProcessedEvent)
if gameProcessedEvent then return end
if running then
-- Reset stuff or whatever you wanna do
end
end