I've been trying to make a double tap script but nothing is working :/
if input.KeyCode == Enum.KeyCode.D or input.KeyCode == Enum.KeyCode.Right and doubleTime == false then doubleTime = true wait(.5) if doubleTime == true then humanoid.WalkSpeed = 24 print("run") else humanoid.WalkSpeed = 16 end end
this is one of the attempts I did also in a renderstepped event the doubleTime = false after a wait but this still does not work correctly I want it to be like if I press d-d in under 1.1 seconds I start sprinting.
thanks for taking the time reading or helping me. ~KIHeros
(this question was rushed...)
The common way to make a double click or double tap is with use of tick()
. This lets you compare the time when they last clicked to the current time. If there's only a slight difference between the times of last click and current click, treat it as a double click.
local lastTapTime = tick() function onTap() if tick() - lastTapTime < 1 then print("double Click!") end lastTapTime = tick() end
local key = "f" local num = 0 -- don't change local reqnum = 2 -- how many taps local waitTime = 1.1 function add() num = num + 1 end num.Changed:connect(function() if num == reqnum then sprint() -- func for your sprinting return elseif num == 0 then return end wait(waitTime) if num < reqnum then num = 0 end end) local context = game:GetService("ContextActionService") context:BindAction("Tap",add,false,key)
This should do it.
Adds one every time you tap, when it reaches reqnum, it does the function (in this case, sprint).