Double Tap for getting BodyVelocity

Hey what am I trying?

I am trying to do a small Dash system so the Humanoid has to press two times the same input to get a BodyVelocity but it seems not working.

This is what I have been tried so far

local Players = game:GetService('Players')
local UserInputService = game:GetService('UserInputService')
local ReplicatedStorage = game:GetService('ReplicatedStorage')

local player = Players.LocalPlayer
local character: Model = player.Character or player.CharacterAdded:Wait()
local rootPart = character:WaitForChild('HumanoidRootPart')
local Humanoid = character:WaitForChild("Humanoid")

local lastDash = tick()
local min = .5

local function Dash()
	local BodyVelocity = Instance.new("BodyVelocity")
	BodyVelocity.MaxForce = Vector3.new(10000,1,10000) 
	BodyVelocity.Velocity = Humanoid.MoveDirection * 150
	BodyVelocity.Parent = rootPart
	wait(1)
	BodyVelocity:Destroy()
end

UserInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.W then
		local now = tick()

		if now - lastDash <= min then
			Dash()
			lastDash = now
		end
	elseif  input.KeyCode == Enum.KeyCode.A then
		local now = tick()

		if now - lastDash <= min then
			Dash()
			lastDash = now
		end
	elseif  input.KeyCode == Enum.KeyCode.D then
		local now = tick()

		if now - lastDash <= min then
			Dash()
			lastDash = now
		end
	elseif  input.KeyCode == Enum.KeyCode.S then
		local now = tick()

		if now - lastDash <= min then
			Dash()
			lastDash = now
		end
	end
end)

below code should works like you wanted

--Move this local script to under of StarterCharacterScripts
local UserInputService = game:GetService('UserInputService')
local character = script.Parent
local rootPart = character:WaitForChild('HumanoidRootPart')
local Humanoid = character:WaitForChild("Humanoid")

function Dash(direction)
	--[[
		you can put if/else logic to here for spesific directions of dash
	]]
	local BodyVelocity = Instance.new("BodyVelocity")
	BodyVelocity.MaxForce = Vector3.new(10000,1,10000) 
	BodyVelocity.Velocity = Humanoid.MoveDirection * 150
	BodyVelocity.Parent = rootPart
	wait(1)
	BodyVelocity:Destroy()
end

local lastDash = tick()
local lastKey
UserInputService.InputBegan:Connect(function(input)
	if lastKey == input.KeyCode and math.abs(tick() - lastDash) <= .5 then
		if input.KeyCode == Enum.KeyCode.W then
			Dash("front")
		elseif  input.KeyCode == Enum.KeyCode.A then
			Dash("left")
		elseif  input.KeyCode == Enum.KeyCode.D then
			Dash("right")
		elseif  input.KeyCode == Enum.KeyCode.S then
			Dash("back")
		end
		lastKey = nil
	end
        lastDash = tick()
	lastKey = input.KeyCode
end)

where did you put the script seems not working

sorry, it was my fault now i fixed it on original reply