Hey. I’ve been looking to make a dash to a game that I am working on, but I can’t really think of a way of making the dash action itself. Here is the script so far that I am using, with a video:
https://streamable.com/wxwfkf
local userInputService = game:GetService("UserInputService");
local tweenService = game:GetService("TweenService");
local players = game:GetService("Players");
local localPlayer = players.LocalPlayer;
local cooldown = script:WaitForChild("Cooldown");
local keys = {
Enum.KeyCode.A;
Enum.KeyCode.S;
Enum.KeyCode.D;
Enum.KeyCode.W;
};
local currentKey = nil;
function input_Began(input, gpe)
if gpe then return end;
if cooldown.Value then return end;
if not table.find(keys, input.KeyCode) then return end;
if input.KeyCode == Enum.KeyCode.A then
currentKey = Enum.KeyCode.A
local pressTime = tick();
local isPressedAgain = false;
repeat wait()
local function input_Began2(i, g)
if g or not table.find(keys, i.KeyCode) then return end;
if input.KeyCode == Enum.KeyCode.A then
isPressedAgain = true
end
end
userInputService.InputBegan:Connect(input_Began2)
until isPressedAgain == true or tick() - pressTime >= 0.5
if isPressedAgain and currentKey == Enum.KeyCode.A then
tweenService:Create(script.Parent:WaitForChild("Dash").Line, TweenInfo.new(.5), {Size = UDim2.new(0, 0, 1, 0)}):Play()
tweenService:Create(script.Parent:WaitForChild("Dash").Cooldown, TweenInfo.new(.5), {TextTransparency = 0}):Play()
cooldown.Value = true
wait(.7)
tweenService:Create(script.Parent:WaitForChild("Dash").Line, TweenInfo.new(.5), {Size = UDim2.new(1, 0, 1, 0)}):Play()
tweenService:Create(script.Parent:WaitForChild("Dash").Cooldown, TweenInfo.new(1.3), {TextTransparency = 1}):Play()
wait(1.3)
cooldown.Value = false
end
end
if input.KeyCode == Enum.KeyCode.S then
currentKey = Enum.KeyCode.S
local pressTime = tick();
local isPressedAgain = false;
repeat wait()
local function input_Began2(i, g)
if g or not table.find(keys, i.KeyCode) then return end;
if input.KeyCode == Enum.KeyCode.S then
isPressedAgain = true
end
end
userInputService.InputBegan:Connect(input_Began2)
until isPressedAgain == true or tick() - pressTime >= 0.5
if isPressedAgain and currentKey == Enum.KeyCode.S then
tweenService:Create(script.Parent:WaitForChild("Dash").Line, TweenInfo.new(.5), {Size = UDim2.new(0, 0, 1, 0)}):Play()
tweenService:Create(script.Parent:WaitForChild("Dash").Cooldown, TweenInfo.new(.5), {TextTransparency = 0}):Play()
cooldown.Value = true
wait(.7)
tweenService:Create(script.Parent:WaitForChild("Dash").Line, TweenInfo.new(.5), {Size = UDim2.new(1, 0, 1, 0)}):Play()
tweenService:Create(script.Parent:WaitForChild("Dash").Cooldown, TweenInfo.new(1.3), {TextTransparency = 1}):Play()
wait(1.3)
cooldown.Value = false
end
end
if input.KeyCode == Enum.KeyCode.D then
currentKey = Enum.KeyCode.D
local pressTime = tick();
local isPressedAgain = false;
repeat wait()
local function input_Began2(i, g)
if g or not table.find(keys, i.KeyCode) then return end;
if input.KeyCode == Enum.KeyCode.D then
isPressedAgain = true
end
end
userInputService.InputBegan:Connect(input_Began2)
until isPressedAgain == true or tick() - pressTime >= 0.5
if isPressedAgain and currentKey == Enum.KeyCode.D then
tweenService:Create(script.Parent:WaitForChild("Dash").Line, TweenInfo.new(.5), {Size = UDim2.new(0, 0, 1, 0)}):Play()
tweenService:Create(script.Parent:WaitForChild("Dash").Cooldown, TweenInfo.new(.5), {TextTransparency = 0}):Play()
cooldown.Value = true
wait(.7)
tweenService:Create(script.Parent:WaitForChild("Dash").Line, TweenInfo.new(.5), {Size = UDim2.new(1, 0, 1, 0)}):Play()
tweenService:Create(script.Parent:WaitForChild("Dash").Cooldown, TweenInfo.new(1.3), {TextTransparency = 1}):Play()
wait(1.3)
cooldown.Value = false
end
end
if input.KeyCode == Enum.KeyCode.W then
currentKey = Enum.KeyCode.W
local pressTime = tick();
local isPressedAgain = false;
repeat wait()
local function input_Began2(i, g)
if g or not table.find(keys, i.KeyCode) then return end;
if input.KeyCode == Enum.KeyCode.W then
isPressedAgain = true
end
end
userInputService.InputBegan:Connect(input_Began2)
until isPressedAgain == true or tick() - pressTime >= 0.5
if isPressedAgain and currentKey == Enum.KeyCode.W then
tweenService:Create(script.Parent:WaitForChild("Dash").Line, TweenInfo.new(.5), {Size = UDim2.new(0, 0, 1, 0)}):Play()
tweenService:Create(script.Parent:WaitForChild("Dash").Cooldown, TweenInfo.new(.5), {TextTransparency = 0}):Play()
cooldown.Value = true
wait(.7)
tweenService:Create(script.Parent:WaitForChild("Dash").Line, TweenInfo.new(.5), {Size = UDim2.new(1, 0, 1, 0)}):Play()
tweenService:Create(script.Parent:WaitForChild("Dash").Cooldown, TweenInfo.new(1.3), {TextTransparency = 1}):Play()
wait(1.3)
cooldown.Value = false
end
end
end;
userInputService.InputBegan:Connect(input_Began)