I know you asked for a way to do it and not necessarily the script itself, but I have no idea how I would describe the script so I just created it below. It should work.
local UIS = game:GetService("UserInputService")
local LastPress = 0
local CertainPeriodOfTime = 60 -- seconds
UIS.InputBegan:Connect(function(key)
if key.KeyCode = Enum.KeyCode.W then
if os.time() - LastPress < CertainPeriodOfTime then
--Then the user has pressed W twice in the period of time
end
LastPress = os.time()
end
end)
Inside the user input function, check if a variable is true or false. If it is false, set it to true, wait X seconds, then set it to false. If it is true, meaning the player has clicked it twice in X seconds, execute the code you want to.
This is a pretty simple solution, simply get the time that the first time they press w, then subtract is by the second time:
local UIS = game:GetService("UserInputService")
local PreviousInput = 0 -- Sets the variable even before anything is pressed to shorten code
local TimeThreshold = 1 -- The time to detect 2 "w" keys pressed down
UIS.InputBegan:Connect(function(Key)
if Key.KeyCode == Enum.KeyCode.W then
if tick() - PreviousInput <= TimeThreshold then -- Checks if the current time subtracted by the previous time is smaller or equal to the TimeThreshold
-- do something
end
else
PreviousInput = tick() -- Makes it the current time
end
end)
PreviousInput should have been set to 0 at the start of the game, otherwise the user could simply press W once when the game starts and have tick() - PreviousInput be less than TimeThreshold.
I know this is a little late, but wouldn’t this work also?? Assuming the wait() is the amount of time you wanna wait between clicks if it should work. For this I just made it so it’s double tap to sprint.
local char = script.Parent
local hum = char:WaitForChild("Humanoid")
local uis = game:GetService("UserInputService")
local canSprint = false
uis.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.W and canSprint == false then
canSprint = true
wait(0.4)
canSprint = false
elseif key.KeyCode == Enum.KeyCode.W and canSprint == true then
hum.WalkSpeed = 50
end
end)
uis.InputEnded:Connect(function(key)
if key.KeyCode == Enum.KeyCode.W and canSprint == false then
hum.WalkSpeed = 16
elseif key.KeyCode == Enum.KeyCode.W and canSprint == true then
hum.WalkSpeed = 50
end
end)