As the title says, I want to make mashing a key (like E) make a timer (5s) go by faster.
For example, I did something in the game and now I have to wait 5s, however, if I start mashing the E key, the timer will decrease in length, making the total wait time 1s instead of 5s
I tried using for loops, but, i can’t really wrap my head around it.
I’m more or less talking about repeatedly pressing the button, but the timer doesn’t go back down, in this case, it just decreases the time by like 0.1s with every key press.
just calculate how fast the player is pressing the key, every second (or whatever interval you want), add one to a variable that contains the number of key presses and check that number every time and reset it every second.
In this example I use a remote event to trigger the timer, please ask me if you are confused on some parts.
local uis = game:GetService("UserInputService")
local rs = game:GetService("RunService")
local timer = 5
local minusamount = 0.1
local keydown
game:GetService("ReplicatedStorage").Event.OnClientEvent:Connect(function()
repeat
wait(1)
if keydown then
timer = timer - 1 + minusamount
print(timer)
else
timer = timer - 1
print(timer)
end
until timer == 0 or timer < 0
print("done")
uis.InputBegan:Connect(function(input, processed)
if input.KeyCode == Enum.KeyCode.E and processed == false then
keydown = true
wait(0.1)
keydown = false
end
end)
uis.InputEnded:Connect(function(input, processed)
if input.KeyCode == Enum.KeyCode.E then
keydown = false
end
end)
end)
This script is a localscript and is located in starterplayerscripts