Character Stop moving problem when clicking on a keyboard key

I am working on dash system. However, when I tested my dash system, I found an issue.
It’s not about error. When I dash, there will be a 3 second cooldown until I will be able to dash again.
However, while the cooldown, when I click Q+D for dash, my character stops moving for a few seconds. When I start to spam click to Q+D to dash, I completely cannot move until I stop clicking. Why is that happening any ideas?

Here is my script.

Script: Local Script
Location: StarterCharacterScript

Note: I user LinearVelocity for my dash to work.

local plr = game.Players.LocalPlayer
local chr = script.Parent
local Root = chr:WaitForChild("HumanoidRootPart")
local Hum = chr:WaitForChild("Humanoid")

local User = game:GetService("UserInputService")
local DashEvent = game.ReplicatedStorage["Dash Event"]
local Air = Enum.Material.Air

local BinFunc = script.Parent

local RightLeft_Dash = false

local Controls = require(game.Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule")):GetControls()

local Vel


User.InputBegan:Connect(function(key, processed)
	if processed then return end
	
	if key.KeyCode == Enum.KeyCode.Q then
		
		
		Vel = Instance.new("LinearVelocity", Root)
		local Attach = Instance.new("Attachment", Root)

		Vel.MaxForce = math.huge
		Vel.VelocityConstraintMode = Enum.VelocityConstraintMode.Vector
		Vel.Attachment0 = Attach
		Vel.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
		Attach.WorldPosition = chr:FindFirstChild("HumanoidRootPart").AssemblyCenterOfMass
		
		
		if User:IsKeyDown(Enum.KeyCode.D) and RightLeft_Dash == false then
			
			RightLeft_Dash = true
			
			if Hum.FloorMaterial == Air then
				
				
				Vel.VectorVelocity = Vector3.new(73,-28,0)
				DashEvent:FireServer("Right Dash")
				
			
				
				
			else
				
				Vel.VectorVelocity = Vector3.new(73,0,0)
				DashEvent:FireServer("Right Dash")
	
			end
			
			task.spawn(function()
				task.wait(3)
				RightLeft_Dash = false
			end)
			
		end
		
		
		game.Debris:AddItem(Vel, 0.2)
		game.Debris:AddItem(Attach, 0.2)
		
		
	end
	

	
end)

User.InputEnded:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.D and Vel then
		Vel.VectorVelocity = Vector3.new(0,0,0)
	end
end)

Here is the video proof what I am talking about.

My character stops automatically when I click a key on my keyboard.

Can you show the server side script too?

there is no server-side script. I use only this one for my dash system.

I am thinking that it might be cause of user input.

You’re using the keycode D. That’s why. You should detect movedirection instead.

How can I do that? I am not that good at scripting :sweat_smile:

Humanoid.Movedirection.

use that to control the dash instead,
this code is only example

dash.velocity = humanoid.movedirection*50 -- now it will be a lot more simple and you can change the 50 to any number you want that controls the speed/force

Thank you, my friend, I also tried to research what is move direction. However, it’s not helped me to fix my problem. I still have same issue. But I will try to solve it. I feel like I am very close to solving it! :grin:

1 Like

I Solved it!

I still don’t know why I had that problem. Maybe because I used my script in CharacterScripts.
So, I created 2 separate scripts.

One is local script, which I put to PlayerScripts.

Another script was Server script, which I put to ServerScriptService.

Local Scripts was creating a number, between 1-4 index, and firing that same number to Remote Event in Replicated storage, while the server script in server script service was taking that number and making player to dash. Here is the clear example.

Local Script in Player Script:

local User = game:GetService("UserInputService")
local DashEvent = game.ReplicatedStorage["Dash Event"]

local Q_W = false
local Q_S = false
local Q_D = false
local Q_A = false
local Q_Key = Enum.KeyCode.Q

local Cooldown_1 = false
local Cooldown_2 = false

User.InputBegan:Connect(function(Input, isProcessed)
	if Input.UserInputType == Enum.UserInputType.Keyboard and not isProcessed then
		
		if Input.KeyCode == Q_Key then
			
			for i, v in pairs({Q_W, Q_S, Q_D, Q_A}) do
				
				if (i == 1 or i == 2) and v == true and Cooldown_1 == false then
					
					Cooldown_1 = true
					DashEvent:FireServer(i)
					print(i)
					task.wait(3)
					Cooldown_1 = false
					
				elseif (i == 3 or i == 4) and v == true and Cooldown_2 == false then
					
					Cooldown_2 = true
					DashEvent:FireServer(i)
					print(i)
					task.wait(3)
					Cooldown_2 = false
				
					
				end
				
			end
			
		elseif Input.KeyCode == Enum.KeyCode.W then
			Q_W = true
		elseif Input.KeyCode == Enum.KeyCode.S then
			Q_S = true
		elseif Input.KeyCode == Enum.KeyCode.D then
			Q_D = true
		elseif Input.KeyCode == Enum.KeyCode.A then
			Q_A = true
		
		end
		
	end
	
end)

User.InputEnded:Connect(function(Input, isProcessed)
	if Input.UserInputType == Enum.UserInputType.Keyboard and not isProcessed then
		if Input.KeyCode == Enum.KeyCode.W then
			Q_W = false
		elseif Input.KeyCode == Enum.KeyCode.S then
			Q_S = false
		elseif Input.KeyCode == Enum.KeyCode.D then
			Q_D = false
		elseif Input.KeyCode == Enum.KeyCode.A then
			Q_A = false

		end
		
	end
	
end)



Server Script in ServerScriptService.

local DashEvent = game.ReplicatedStorage["Dash Event"]

local Dash_Vector = {
	[1] = Vector3.new(-1, -2, -45),
	[2] = Vector3.new(-1, -2, 45),
	[3] = Vector3.new(45, -2, -1),
	[4] = Vector3.new(-45, -2, -1)
}


DashEvent.OnServerEvent:Connect(function(plr, Direction)
	
	local chr = plr.Character
	local Root = chr:WaitForChild("HumanoidRootPart")
	local Hum = chr:WaitForChild("Humanoid")
	
	local Debris = game.Debris

	local Attach = Instance.new("Attachment", Root)
	local Vel = Instance.new("LinearVelocity", Attach)

	Vel.MaxForce = math.huge
	Vel.VelocityConstraintMode = Enum.VelocityConstraintMode.Vector
	Vel.VectorVelocity = Dash_Vector[Direction]
	Vel.Attachment0 = Attach
	Vel.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
	Attach.WorldPosition = chr:FindFirstChild("HumanoidRootPart").AssemblyCenterOfMass

	
	Debris:AddItem(Attach, 0.4)
	Debris:AddItem(Vel, 0.4)
	
end)

I learned it from this tutorial:

[2000 Sub Special] How to make the Dash System from The Strongest Battlegrounds! (Roblox Scripting) - YouTube

However, I did some changes to the script, now I have 2 separated dashes, Front/Back Dash, which I set Cooldown_1 and Left/Right Dash which I set Cooldown_2.

Now finally I solved it😄

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.