How i can upgrade dash system?

I understand roughly how I can improve the code, but I don’t know how to implement it…

here code:

local Rp = game:GetService("ReplicatedStorage")
local Debris = game:GetService("Debris")



local remotes = Rp:WaitForChild("Remotes")

local DashRemote = remotes.Dash

local function NormalizeVector(vector: Vector3 | Vector3int16 | Vector2 | Vector2int16)
	return if (vector.Magnitude == 0) then vector else vector.Unit
end

local function Dash(char, attachment, hrpLookVector, button, cameralookvector)	
	
	if button then
		local lv = Instance.new("LinearVelocity")
		lv.MaxForce = math.huge
		local dashSpeed = 100 -- Новая скорость дэша
		lv.VectorVelocity = hrpLookVector.Unit * dashSpeed

		lv.Attachment0 = attachment
		lv.Parent = char	
		char:SetPrimaryPartCFrame(CFrame.new(char.PrimaryPart.Position, char.PrimaryPart.Position + Vector3.new(cameralookvector.X, 0, cameralookvector.Z)))
		char:SetAttribute("Dashing", true)
		Debris:AddItem(lv, 1)
		task.wait(1)
		char:SetAttribute("Dashing", false)
		
	end
end

DashRemote.OnServerEvent:Connect(function(player, a,d,s,w, CameraLookVector)
	
	local char = player.Character
	local humRP = char:FindFirstChild("HumanoidRootPart")
	local hum = char:FindFirstChildOfClass("Humanoid")
	
	local plrMoveDirection = hum.MoveDirection
	local plrLookVector = humRP.CFrame.LookVector
	
	
	local attach = humRP:FindFirstChild("RootAttachment")
	
	local Dashing = char:GetAttribute('Dashing')
	
	if a then
		Dash(char, attach, plrMoveDirection, a, CameraLookVector)
	elseif d then
		Dash(char, attach, plrMoveDirection, d, CameraLookVector)
	elseif s then
		Dash(char, attach, plrMoveDirection, s, CameraLookVector)
	elseif w then
		Dash(char, attach, plrMoveDirection, w, CameraLookVector)
	end
	


	
end)
1 Like

Here are my two cents on how I would improve the code.

Readability

  • Some of your variables don’t have meaningful or have vague names which can cause confusion when you have to reread the code again.
  • Unusual use of vertical whitespaces.

Take a look at these guides on how to properly organise a script to improve readability.
https://roblox.github.io/lua-style-guide/

Model:SetPrimaryPartCFrame is deprecated. Use Model:PivotTo() instead.

1 Like

Are there ready-made libraries or modules to simplify writing code?

No unfortunately, I can’t find any libraries/plugins for such purpose.