I'm trying to make a double jump script I know how to make the player jump twice but I do not know how to make it work by double tapping w :P
My attempt below V
Input.InputBegan:connect(function(KeyInput) if KeyInput.KeyCode == Enum.KeyCode.W then Character.Humanoid.Jump = true if KeyInput.KeyCode == Enum.KeyCode.W then Character.Torso.Velocity = Vector3.new(0, 60, 0) end end end)
But that does not work :/ Can someone show me how to do this?
Thanks ~KiHeros
You're not thinking practically. You're thinking that by putting 2 if statements then it will check if they hit the button 2 times? It checks twice, if they hit the button. Not checks if they hit the button twice. Understand?
You need to take advantage of the tick function.
returns the amount of time, in seconds, has passed since the epoch, or January 1, 1970.
By using this function you can get the time before the jump button was pressed, and after. If the difference between the two is less than a set time.. then activate a double jump.
--Last time the button was pressed local lastTime = tick() Input.InputBegan:connect(function(KeyInput) --Check the keycode if KeyInput.KeyCode == Enum.KeyCode.W then --Get tick() time local now = tick() --compare tick()'s local difference = (now - lastTime) --Check if difference is less than a second if difference <= 1 then --if so, enable double jump Character.Torso.Velocity = Vector3.new(0, 60, 0) else --Otherwise, normal jump. Character.Humanoid.Jump = true end end end)