In my webswinging game, when the player holds down the E key they swing and when they let go of E they release from the web. I want to add a web dash type ability when the player presses or taps the E key.
-Tapping E will trigger the web dash,
-Holding E will trigger a web swing,
You can connect an event where the player releases E within the number of seconds you want E to be held for. If E is still held, activate web swing. It goes something like this.
HoldE = true
webdash = true
Connect to release E:
if webdash still true trigger web dash
HoldE = false
wait for some second
webdash = false
if HoldE still true trigger web swing
you would use InputBegan and InputEnded to detect the time.
local UIS = game:GetService("UserInputService")
local EPressed = nil
UIS.InputBegan:Connect(function(key, typing)
if not typing then
if key.KeyCode == Enum.KeyCode.E then
EPressed = tick()
end
end
end)
UIS.InputEnded:Connect(function(key, typing)
if key.KeyCode == Enum.KeyCode.E then
if EPressed then
if tick()-EPressed <= 0.2 then
--pressed
else
--held
end
EPressed = nil
end
end
end)