Tutorial · Gameplay

How to make a dash in Roblox Studio (Q to dash)

A dash is a short, fast burst in the direction the player is moving: the move that makes combat games and obbies feel quick. In Roblox it is a LocalScript that listens for Q, then pushes the character with a LinearVelocity constraint for a fraction of a second. This guide builds a dash that works with a keyboard, a gamepad and a phone button, waits for a cooldown, allows one dash in the air, and shows a trail behind the player that everyone in the server can see.

Updated 14 November 20269 min readIntermediateLuauWritten by

In short

Put a LocalScript in StarterPlayerScripts. Bind Q with ContextActionService:BindAction("Dash", onDash, true, Enum.KeyCode.Q, Enum.KeyCode.ButtonB); the true adds a Dash button on phones. On a press, check the cooldown, then add a LinearVelocity to the root part in Plane mode that holds 70 studs per second along Humanoid.MoveDirection, and destroy it after 0.18 seconds.

  • The dash runs on the player's device, because each device moves its own character. A server Script that pushes the character fights the player's own physics.
  • Plane mode controls only the horizontal speed, so gravity still works and a dash off a ledge falls normally.
  • The server checks its own cooldown before it shows the trail, so a cheater spamming the RemoteEvent gets no extra effects.

Get the script

Dash script on Q with cooldown and phone button

One LocalScript in StarterPlayerScripts: press Q, B on a gamepad or the Dash button on a phone to dash where you are moving, with a cooldown.

LocalScript in StarterPlayerScripts named DashClient
-- LocalScript in StarterPlayerScripts named DashClient.
-- Press Q (B on a gamepad, or the Dash button on a phone) to dash the way you are moving.
local ContextActionService = game:GetService("ContextActionService")
local Debris = game:GetService("Debris")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")

local DASH_SPEED = 70 -- studs per second during the dash (walking is 16)
local DASH_SECONDS = 0.18 -- how long the push lasts
local DASH_COOLDOWN = 1.5 -- seconds between dashes
local AIR_DASHES = 1 -- dashes allowed before touching the ground again

local player = Players.LocalPlayer
local lastDash = -math.huge
local airDashesUsed = 0

local function getHumanoid(): Humanoid?
	local character = player.Character
	local humanoid = character and character:FindFirstChildOfClass("Humanoid")
	if humanoid and humanoid.Health > 0 then
		return humanoid
	end
	return nil
end

local function dash()
	local humanoid = getHumanoid()
	local root = humanoid and humanoid.RootPart
	if not (humanoid and root) or humanoid.Sit then
		return -- no dash while dead or sitting: a seated character would shove its seat
	end
	local now = os.clock()
	if now - lastDash < DASH_COOLDOWN then
		return
	end
	local inAir = humanoid.FloorMaterial == Enum.Material.Air
	if inAir and airDashesUsed >= AIR_DASHES then
		return
	end
	local attachment = root:FindFirstChild("RootAttachment")
	if not (attachment and attachment:IsA("Attachment")) then
		return
	end
	lastDash = now
	if inAir then
		airDashesUsed += 1
	end

	-- Dash the way the player is moving, or the way they face when standing still
	local direction = humanoid.MoveDirection
	if direction.Magnitude < 0.1 then
		direction = root.CFrame.LookVector
	end
	direction = Vector3.new(direction.X, 0, direction.Z).Unit

	-- Plane mode holds the speed on the X and Z axes only, so gravity still works
	local velocity = Instance.new("LinearVelocity")
	velocity.Attachment0 = attachment
	velocity.RelativeTo = Enum.ActuatorRelativeTo.World
	velocity.VelocityConstraintMode = Enum.VelocityConstraintMode.Plane
	velocity.PrimaryTangentAxis = Vector3.xAxis
	velocity.SecondaryTangentAxis = Vector3.zAxis
	velocity.PlaneVelocity = Vector2.new(direction.X, direction.Z) * DASH_SPEED
	velocity.MaxForce = math.huge
	velocity.Parent = root
	Debris:AddItem(velocity, DASH_SECONDS)

	-- Ask the server for the trail (Step 3). Skipped if DashServer is not in the game.
	local remote = ReplicatedStorage:FindFirstChild("DashEffect")
	if remote and remote:IsA("RemoteEvent") then
		remote:FireServer()
	end
end

local function onDash(_name: string, state: Enum.UserInputState, _input: InputObject): Enum.ContextActionResult
	if state == Enum.UserInputState.Begin then
		dash()
	end
	return Enum.ContextActionResult.Pass
end

-- One call binds the key, a gamepad button and, on touch screens, an on-screen button
ContextActionService:BindAction("Dash", onDash, true, Enum.KeyCode.Q, Enum.KeyCode.ButtonB)
ContextActionService:SetTitle("Dash", "Dash")
ContextActionService:SetPosition("Dash", UDim2.new(1, -170, 1, -120))

-- Every frame: refill the air dash on the ground, and show the cooldown on the phone button
RunService.Heartbeat:Connect(function()
	local humanoid = getHumanoid()
	if humanoid and humanoid.FloorMaterial ~= Enum.Material.Air then
		airDashesUsed = 0
	end
	local left = DASH_COOLDOWN - (os.clock() - lastDash)
	ContextActionService:SetTitle("Dash", if left > 0 then string.format("%.1f", left) else "Dash")
end)

player.CharacterAdded:Connect(function()
	airDashesUsed = 0
end)

RoCode builds it in the place you have open in Roblox Studio, on Windows or macOS with a desktop browser; on a phone the button sends the prompt and the link to your computer. Free to start, with free credits every day. More Roblox Studio scripts

Where to put it

Explorer: the LocalScript dashes, the Script draws the trail for everyone
StarterPlayer
  StarterPlayerScripts
    DashClient LocalScript new
ServerScriptService
  DashServer Script (new, Step 3)

Settings you can change

DASH_SPEEDIn the script
Studs per second during the dash. Walking is 16. Default: 70.
DASH_SECONDSIn the script
How long the push lasts. Speed times time is the distance: about 12.6 studs. Default: 0.18.
DASH_COOLDOWNIn the script
Seconds before the player can dash again. Default: 1.5.

Step 1 works on its own. Step 3 adds the trail other players see; without DashServer the dash still works and the client skips the trail.

What a cheater can and cannot doThe player's device moves its own character, so a cheater can dash with no cooldown whatever this script says. The server only trusts itself for the trail: Step 3 keeps its own cooldown per player and ignores extra requests.

Type-checked with luau-lsp strict against Roblox's API definitions on 14 November 2026. Not playtested in Studio yet: press Play and watch the Output window before you publish.

Prompt for RoCode

Add a dash to my game: a LocalScript in StarterPlayerScripts that binds Q, the gamepad B button and a phone button with ContextActionService, dashes in the move direction with a LinearVelocity in Plane mode at 70 studs per second for 0.18 seconds, has a 1.5 second cooldown shown on the button, allows one dash in the air, and fires a RemoteEvent so a server Script with its own cooldown shows a short trail behind the player.

On this page
  1. Get the script
  2. How it works
  3. 1. LocalScript
  4. 2. Explained
  5. 3. Server trail
  6. 4. ApplyImpulse
  7. 5. Test
  8. Common errors
  9. With RoCode
  10. Questions
  11. Sources

How a dash works in Roblox

A Roblox character walks at its WalkSpeed, 16 studs per second by default. A dash adds a short burst far above that. There are two ways to push a character:

Two ways to push a character
MethodHow it worksGood for
LinearVelocity constraintHolds a set speed for as long as it exists, then you destroy it.A dash of an exact distance every time, on the ground or in the air.
BasePart:ApplyImpulseOne instant shove. Friction and the Humanoid slow it down afterwards.Knockback and explosions, or a dash that should feel like a shove.

This guide uses LinearVelocity, because the distance is the same on every surface. Step 4 shows the ApplyImpulse version. Older tutorials use BodyVelocity, which Roblox has deprecated in favour of LinearVelocity.

Step 1: The dash LocalScript

  1. In the Explorer, expand StarterPlayer, hover over StarterPlayerScripts, click + and insert a LocalScript. Name it DashClient.
  2. Replace its contents with the code below.
  3. Press Play, walk in any direction and press Q.
LocalScript in StarterPlayerScripts named DashClient
-- LocalScript in StarterPlayerScripts named DashClient.
-- Press Q (B on a gamepad, or the Dash button on a phone) to dash the way you are moving.
local ContextActionService = game:GetService("ContextActionService")
local Debris = game:GetService("Debris")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")

local DASH_SPEED = 70 -- studs per second during the dash (walking is 16)
local DASH_SECONDS = 0.18 -- how long the push lasts
local DASH_COOLDOWN = 1.5 -- seconds between dashes
local AIR_DASHES = 1 -- dashes allowed before touching the ground again

local player = Players.LocalPlayer
local lastDash = -math.huge
local airDashesUsed = 0

local function getHumanoid(): Humanoid?
	local character = player.Character
	local humanoid = character and character:FindFirstChildOfClass("Humanoid")
	if humanoid and humanoid.Health > 0 then
		return humanoid
	end
	return nil
end

local function dash()
	local humanoid = getHumanoid()
	local root = humanoid and humanoid.RootPart
	if not (humanoid and root) or humanoid.Sit then
		return -- no dash while dead or sitting: a seated character would shove its seat
	end
	local now = os.clock()
	if now - lastDash < DASH_COOLDOWN then
		return
	end
	local inAir = humanoid.FloorMaterial == Enum.Material.Air
	if inAir and airDashesUsed >= AIR_DASHES then
		return
	end
	local attachment = root:FindFirstChild("RootAttachment")
	if not (attachment and attachment:IsA("Attachment")) then
		return
	end
	lastDash = now
	if inAir then
		airDashesUsed += 1
	end

	-- Dash the way the player is moving, or the way they face when standing still
	local direction = humanoid.MoveDirection
	if direction.Magnitude < 0.1 then
		direction = root.CFrame.LookVector
	end
	direction = Vector3.new(direction.X, 0, direction.Z).Unit

	-- Plane mode holds the speed on the X and Z axes only, so gravity still works
	local velocity = Instance.new("LinearVelocity")
	velocity.Attachment0 = attachment
	velocity.RelativeTo = Enum.ActuatorRelativeTo.World
	velocity.VelocityConstraintMode = Enum.VelocityConstraintMode.Plane
	velocity.PrimaryTangentAxis = Vector3.xAxis
	velocity.SecondaryTangentAxis = Vector3.zAxis
	velocity.PlaneVelocity = Vector2.new(direction.X, direction.Z) * DASH_SPEED
	velocity.MaxForce = math.huge
	velocity.Parent = root
	Debris:AddItem(velocity, DASH_SECONDS)

	-- Ask the server for the trail (Step 3). Skipped if DashServer is not in the game.
	local remote = ReplicatedStorage:FindFirstChild("DashEffect")
	if remote and remote:IsA("RemoteEvent") then
		remote:FireServer()
	end
end

local function onDash(_name: string, state: Enum.UserInputState, _input: InputObject): Enum.ContextActionResult
	if state == Enum.UserInputState.Begin then
		dash()
	end
	return Enum.ContextActionResult.Pass
end

-- One call binds the key, a gamepad button and, on touch screens, an on-screen button
ContextActionService:BindAction("Dash", onDash, true, Enum.KeyCode.Q, Enum.KeyCode.ButtonB)
ContextActionService:SetTitle("Dash", "Dash")
ContextActionService:SetPosition("Dash", UDim2.new(1, -170, 1, -120))

-- Every frame: refill the air dash on the ground, and show the cooldown on the phone button
RunService.Heartbeat:Connect(function()
	local humanoid = getHumanoid()
	if humanoid and humanoid.FloorMaterial ~= Enum.Material.Air then
		airDashesUsed = 0
	end
	local left = DASH_COOLDOWN - (os.clock() - lastDash)
	ContextActionService:SetTitle("Dash", if left > 0 then string.format("%.1f", left) else "Dash")
end)

player.CharacterAdded:Connect(function()
	airDashesUsed = 0
end)

The script lives in StarterPlayerScripts, so it runs once per player and keeps working through respawns: getHumanoid looks up the current character every time instead of keeping the first one.

Step 2: What each part does

Q, gamepad and a phone button in one call

ContextActionService:BindAction takes an action name, the function to call, whether to make a touch button, and then the inputs. With true as the third argument, Roblox adds an on-screen button on touch devices. SetTitle writes on that button and SetPosition moves it; both do nothing on a computer, so the same code is safe everywhere. Roblox's reference says BindAction can make at most 7 touch buttons, so count them if other scripts add buttons too.

The handler gets the input state. It dashes only on Begin, the press, so holding Q does not dash again on release. A binding only fires while it is the newest one for that key, which means typing a Q in the chat box does not make the player dash.

The push

A LinearVelocity needs an Attachment to act on. Every character's root part already has one called RootAttachment, so the script uses that. In Plane mode, with the X and Z axes as the plane, it controls only the horizontal speed. MaxForce at math.huge means nothing can slow the dash while it lasts. Debris:AddItem destroys the constraint after DASH_SECONDS without pausing the script.

The distance is speed times time: 70 studs per second for 0.18 seconds is about 12.6 studs. Raise DASH_SECONDS for a longer dash, or DASH_SPEED for a snappier one.

Cooldown and air dashes

os.clock() is a timer in seconds. The script saves the time of the last dash and refuses a new one until DASH_COOLDOWN has passed. Humanoid.FloorMaterial is Air when the character is not standing on anything, so the script counts dashes made in the air and resets the count as soon as the character is back on the floor. Set AIR_DASHES to 0 for a ground-only dash.

On a phone, the Dash button shows the seconds left, such as 1.2, and goes back to "Dash" when ready. For a cooldown on a computer screen too, add a TextLabel in a ScreenGui and set its text in the same Heartbeat function. The GUI button guide shows how to build and place one.

A dash animation

To play an animation, make one in the Animation Editor, publish it, and load it on the Humanoid's Animator at the start of dash() with animator:LoadAnimation(animation):Play(). Set its priority to Action so it plays over walking. The animation script guide covers loading and priorities.

Step 3: A trail every player sees

A trail made by a LocalScript only shows on that player's screen. For everyone to see it, the server has to make it. The LocalScript already fires a RemoteEvent called DashEffect after each dash. This Script creates that RemoteEvent, checks its own cooldown so a cheater cannot spam it, and turns on a trail behind the character for half a second.

  1. Hover over ServerScriptService, click + and insert a Script named DashServer.
  2. Paste the code below. It makes the RemoteEvent itself, so there is nothing else to insert.
Script in ServerScriptService named DashServer
-- Script in ServerScriptService named DashServer.
-- Shows a short trail behind a player who dashes. Keeps its own cooldown per player.
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local SERVER_COOLDOWN = 1.2 -- a little under the client's 1.5, so network delay never drops a real dash
local TRAIL_SECONDS = 0.5

local remote = Instance.new("RemoteEvent")
remote.Name = "DashEffect"
remote.Parent = ReplicatedStorage

local lastDash: { [Player]: number } = {}

-- Makes (once per character) a trail between two attachments on the root part
local function getTrail(root: BasePart): Trail
	local existing = root:FindFirstChild("DashTrail")
	if existing and existing:IsA("Trail") then
		return existing
	end
	local top = Instance.new("Attachment")
	top.Name = "DashTrailTop"
	top.Position = Vector3.new(0, 1, 0)
	top.Parent = root
	local bottom = Instance.new("Attachment")
	bottom.Name = "DashTrailBottom"
	bottom.Position = Vector3.new(0, -1, 0)
	bottom.Parent = root

	local trail = Instance.new("Trail")
	trail.Name = "DashTrail"
	trail.Attachment0 = top
	trail.Attachment1 = bottom
	trail.Lifetime = 0.25
	trail.Color = ColorSequence.new(Color3.fromRGB(140, 200, 255))
	trail.Transparency = NumberSequence.new(0.2, 1)
	trail.Enabled = false
	trail.Parent = root
	return trail
end

remote.OnServerEvent:Connect(function(player: Player)
	local now = os.clock()
	if now - (lastDash[player] or -math.huge) < SERVER_COOLDOWN then
		return -- too soon: ignore it
	end
	lastDash[player] = now

	local character = player.Character
	local humanoid = character and character:FindFirstChildOfClass("Humanoid")
	local root = humanoid and humanoid.RootPart
	if not (humanoid and root) or humanoid.Health <= 0 then
		return
	end
	local trail = getTrail(root)
	trail.Enabled = true
	task.delay(TRAIL_SECONDS, function()
		if trail.Parent then
			trail.Enabled = false
		end
	end)
end)

Players.PlayerRemoving:Connect(function(player: Player)
	lastDash[player] = nil
end)

The RemoteEvent carries no arguments, so there is nothing to validate except timing. The server does not take the client's word for the cooldown: it keeps its own times in lastDash. Its cooldown is a bit shorter than the client's, because two real dashes 1.5 seconds apart can arrive closer together after a delay on the network.

The same pattern works for a dash sound or a hit box. A dash that damages players on contact must be checked on the server, the way the combat system guide checks every hit.

Step 4: The ApplyImpulse version

BasePart:ApplyImpulse gives the whole character one instant shove at its centre of mass. The speed it adds depends on mass, so multiply by AssemblyMass to get the same speed for every avatar. Roblox's reference says that for a part owned by a client, as a player's own character is, a client script can call it. This version replaces the push in dash(); use it as a separate LocalScript if you want to compare the two.

LocalScript in StarterPlayerScripts named ImpulseDash
-- LocalScript in StarterPlayerScripts named ImpulseDash (an alternative to DashClient).
-- Press E for an instant shove instead of a held speed.
local ContextActionService = game:GetService("ContextActionService")
local Players = game:GetService("Players")

local DASH_SPEED = 60 -- speed added by the shove, in studs per second
local DASH_COOLDOWN = 1.5

local player = Players.LocalPlayer
local lastDash = -math.huge

local function onDash(_name: string, state: Enum.UserInputState, _input: InputObject): Enum.ContextActionResult
	if state ~= Enum.UserInputState.Begin then
		return Enum.ContextActionResult.Pass
	end
	local character = player.Character
	local humanoid = character and character:FindFirstChildOfClass("Humanoid")
	local root = humanoid and humanoid.RootPart
	local now = os.clock()
	if not (humanoid and root) or humanoid.Health <= 0 or now - lastDash < DASH_COOLDOWN then
		return Enum.ContextActionResult.Pass
	end
	lastDash = now
	local direction = humanoid.MoveDirection
	if direction.Magnitude < 0.1 then
		direction = root.CFrame.LookVector
	end
	direction = Vector3.new(direction.X, 0, direction.Z).Unit
	-- Impulse = mass times the change in speed, so every avatar gets the same speed
	root:ApplyImpulse(direction * DASH_SPEED * root.AssemblyMass)
	return Enum.ContextActionResult.Pass
end

ContextActionService:BindAction("ImpulseDash", onDash, true, Enum.KeyCode.E)
ContextActionService:SetTitle("ImpulseDash", "Shove")

On the ground the shove fades fast: the Humanoid steers the character back to walking speed and friction slows it, so the distance changes with the floor and with whether the player is holding a direction. In the air it travels further. That is why the main script uses LinearVelocity, and why ApplyImpulse suits knockback better than a dash.

Step 5: Test it

  1. Open the Output window (Window menu, then Output) and press Play.
  2. Walk and press Q: you should shoot forward about 12 studs. Press Q again at once: nothing happens until 1.5 seconds have passed.
  3. Jump and press Q in the air: you dash once. A second press in the same jump does nothing.
  4. Stand still and press Q: you dash the way your character faces.
  5. To see the trail as another player would, use the Test tab to start a local server with 2 players and dash with one of them.
  6. To try the phone button, test with Studio's device emulator set to a phone. The button sits near the jump button and counts down after each dash.

Common errors and fixes

If Q does nothing, check the Output window first: a red line names the script and the line.

Pressing Q does nothing

Check that DashClient is a LocalScript in StarterPlayerScripts, not a Script. Then check that no other script binds an action called Dash, such as the stamina script from the sprint guide: the newest binding wins.

The dash goes up into the sky or into the floor

The direction had a vertical part. The script removes it with Vector3.new(direction.X, 0, direction.Z) and uses Plane mode on X and Z. Check that both are still there.

The character keeps sliding after the dash

The LinearVelocity was not destroyed. Check the Debris:AddItem(velocity, DASH_SECONDS) line, and that DASH_SECONDS is a small number like 0.18.

Other players do not see the trail

The trail is made by DashServer, so it has to be a Script in ServerScriptService. If you made the trail in the LocalScript, only you see it.

The dash stops dead on the ground but works in the air

Something is pinning the character, such as an anchored part welded to it or a script that sets the root part's velocity every frame. Check for other movement scripts. LinearVelocity with MaxForce at math.huge is not slowed by friction.

Build it with RoCode

If you would rather not set this up by hand, RoCode can build it in the place you have open. RoCode is an independent AI agent for Roblox Studio, not made by Roblox: you describe the change in a web chat, and its Studio plugin creates the parts and scripts in your Explorer, so there is no code to paste.

You type

Add a dash on Q to my battlegrounds game with a 2 second cooldown, a dash button on phones, one dash in the air, and a blue trail other players can see.

RoCode does
  • Can read your place first to find the scripts you already have, then adds the LocalScript and the server Script next to them
  • Writes the scripts with Create Script and is told to compile-check each one with Check Script
  • Sets an undo point before and after each batch of changes, so Ctrl+Z steps back one batch at a time

After a build, RoCode can run its test robot: it plays your game in Studio and reports PASS or FAIL. It checks only what it chose to test, so try the dash yourself too. How RoCode connects to Studio.

Questions

How do you make a dash script in Roblox?

Bind Q with ContextActionService:BindAction in a LocalScript, and on a press add a LinearVelocity to the character's root part for a fraction of a second. Step 1 has the full script with a cooldown.

How do I add a cooldown to a dash?

Save os.clock() when the player dashes and ignore presses until the cooldown has passed: if now - lastDash < DASH_COOLDOWN then return end.

How do I make a dash button on mobile?

Pass true as the third argument of BindAction. Roblox then adds a touch button, which SetTitle and SetPosition customise.

Should I use BodyVelocity for a dash?

No. Roblox has deprecated BodyVelocity. Use LinearVelocity, or ApplyImpulse for an instant shove.

Why is my dash different on each floor?

You are probably using ApplyImpulse, which friction and the Humanoid slow down. LinearVelocity holds the speed for a set time, so the distance stays the same.

Sources and further reading

How the code was checked: every script on this page passes Luau's strict type checker against Roblox's API definitions (luau-lsp, 14 November 2026). A type check catches misspelt APIs and wrong types, not game logic, so playtest in Studio before you publish.

Try RoCode on your own place.

Free every day, no card required. Install the plugin, describe the feature, and review what lands in Studio.