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)