This is a script, but i dont know how to use 2 of the same letters for Enum.For example i want to make a spritning script that when i press W twice it starts to run.
game:GetService("UserInputService").InputBegan:connect(function(input,gameprocesed) if input.KeyCode == Enum.KeyCode.Z then for i = 1,16 do wait() game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed + 1.5 end end end)
game:GetService("UserInputService").InputEnded:connect(function(input,gameprocesed) if input.KeyCode == Enum.KeyCode.Z then for i = 1,16 do wait() game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed - 1.5 end end end)
game.Players.LocalPlayer.Character:WaitForChild("Humanoid").Died:connect(function() game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16 script.Disabled = true end)
This is actually not that difficult to accomplish.
The primary function to use is tick()
, which represents the time passed since epoch (June 1, 1970), in seconds. Why is this important? Well, the function is used to time certain things, such as a double jump or double click.
First create a variable that presents initial time:
local InitialTick = tick()
Then use the InputBegan
event and check for a desired key:
local uis = game:GetService("UserInputService") uis.InputBegan:Connect(function(input, gpe) if input.KeyCode == Enum.KeyCode.W and not gpe then
Set another variable for the current tick:
local CurrentTick = tick()
Now we check to see if the input received was indeed a double tap, press or click. This is accomplished by subtracting the InitialTick
from the CurrentTick
. If the time between key presses is either less than or exactly 1 second, then count it as a double tap, press or click.
Here's what that would look like:
local TimePassed = CurrentTick - InitialTick if TimePassed <= 1 then -- Enable sprinting game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 50 -- Any desired number end
Followed by the other ends:
end end)
If you also want the double press to be able to disable sprinting, you can use a boolean value and implement it into your code.
Example of doing this along with complete example script:
local uis = game:GetService("UserInputService") local IsSprinting = false local InitialTick = tick() uis.InputBegan:Connect(function(input, gpe) if input.KeyCode == Enum.KeyCode.W and not gpe then local CurrentTick = tick() local TimePassed = CurrentTick - InitialTick if TimePassed <= 1 and not IsSprinting then -- Enable sprinting IsSprinting = true game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 50 -- Any desired number elseif TimePassed <= 1 and IsSprinting then -- Disable sprinting IsSprinting = false game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16 -- The original WalkSpeed of the Humanoid end end end)