Hey I want check if I input 2 times the same input but I have some isuess can somoene help please?
local DashKeys = {
[Enum.KeyCode.W] = 'Forward',
[Enum.KeyCode.A] = 'Left',
[Enum.KeyCode.S] = 'Backward',
[Enum.KeyCode.D] = 'Right'
}
local lastDash = tick()
local min = .5
UserInputService.InputBegan:Connect(function(key, locked)
if locked then return end
if (key.KeyCode == Enum.KeyCode[DashKeys] and tick() - LAST_DASH >= COOLDOWN) then
local now = tick()
if now - lastDash <= min then
print("hey")
ebd
end)
Use another table that contains booleans which represents whether they are pressed down or not. The InputBegan will toggle them true and vice versa with InputEnded.
Forward and Left and Backward was made because I needed to make this:
UserInputService.InputBegan:Connect(function(key, locked)
if locked then return end
if (key.KeyCode == Enum.KeyCode[DashKeys] and tick() - LAST_DASH >= COOLDOWN) then
local now = tick()
local mixedDirection = Vector3.new(0, 0, 0)
local animationCode = 0
for dashKey, directionName in pairs(DashKeys) do
if UserInputService:IsKeyDown(dashKey) then
LAST_DASH = tick()
if now - lastDash <= min then
animationCode += GetAnimationCodeByName(directionName)
local direction = GetDirection[directionName]()
mixedDirection += direction
end
end
end
end)
so how can I fix this problem with using the Table I have been created?
The code could be condensed this way. Only issue I know about this one is the rigidity.
local lastDash = tick()
local lastTap
local min = .5
UserInputService.InputBegan:Connect(function(key, locked)
if locked then return end
if (key.KeyCode == Enum.KeyCode[DashKeys] and tick() - lastDash >= min) then
if lastTap == key.KeyCode then
-- dash!!!
lastDash = tick()
lastTap = nil
else
lastTap = key.KeyCode
end
end
end)