Is mine script for dash is normal?

Here a script! [v2 VERSION]

-[MODULE]-

local module = {}
local antidebounce = false
local runservice = game:GetService("RunService")
local camera = workspace.CurrentCamera

function module:Dash(character, side)
	local rootpart = character:FindFirstChild("HumanoidRootPart")
	local humanoid = character:FindFirstChild("Humanoid")
	local oldwalkspeed = humanoid.WalkSpeed
	local oldjumppower = humanoid.JumpPower
	humanoid.WalkSpeed = 0
	humanoid.JumpPower = 0
	if not rootpart or not humanoid then return end
	local attachment = Instance.new("Attachment", rootpart)
	local velocity = Instance.new("BodyVelocity", attachment)
	velocity.Name = "Dash"
	velocity.MaxForce = Vector3.new(math.huge,0,math.huge)
	velocity.P = 9e9
	velocity.Parent = rootpart
	local animation
	local connection = runservice.Heartbeat:Connect(function(dt)
		if side == Enum.KeyCode.W then
			animation = humanoid:LoadAnimation(game.ReplicatedStorage.Container.CombatAction.Dash.FrontDash)
			for i=50,0,-1 do
				velocity.Velocity = rootpart.CFrame.LookVector * 1 * i
				task.wait()
			end
		elseif side == Enum.KeyCode.S then
			animation = humanoid:LoadAnimation(game.ReplicatedStorage.Container.CombatAction.Dash.BackDash)
			for i=50,0,-1 do
				velocity.Velocity = rootpart.CFrame.LookVector * -1 * 55
				task.wait()
			end
		elseif side == Enum.KeyCode.A then
			animation = humanoid:LoadAnimation(game.ReplicatedStorage.Container.CombatAction.Dash.LeftDash)
			for i=50,0,-1 do
				velocity.Velocity = camera.CFrame.LookVector:Cross(camera.CFrame.UpVector) * -1 * 55
				task.wait()
			end
		elseif side == Enum.KeyCode.D then
			animation = humanoid:LoadAnimation(game.ReplicatedStorage.Container.CombatAction.Dash.RightDash)
			for i=50,0,-1 do
				velocity.Velocity = camera.CFrame.LookVector:Cross(camera.CFrame.UpVector) * 1 * 55
				task.wait()
			end
		end
	end)
	repeat wait() until animation ~= nil
	animation:Play()
	task.wait(0.5)
	attachment:Destroy()
	connection:Disconnect()
	velocity:Destroy()
	humanoid.WalkSpeed = 16
	humanoid.JumpPower = 7.2
end

return module

-[CLIENT]-

--[SERVICES]--
local uis = game:GetService("UserInputService")

--[ATTRIBUTES]--
local plr = game.Players.LocalPlayer
local character = plr.Character 
local events = game.ReplicatedStorage.Container.Combat.Events
local humanoid = character:FindFirstChild("Humanoid")
local animator = humanoid:FindFirstChild("Animator")
local animation = animator:LoadAnimation(game.ReplicatedStorage.Container.Combat.Animations.Blocking)
local DashHolder = require(game.ReplicatedStorage.Modules.CombatSystem.Dash)

--[VALUES]--
local SidedashReload = false
local DashReload = false
local isBlocking = false

--[FUNCTIONS]--
local function Dash()
	local side = Enum.KeyCode.W
	if uis:IsKeyDown(Enum.KeyCode.D) then
		if SidedashReload == true then return end
		side = Enum.KeyCode.D
		SidedashReload = true
	elseif uis:IsKeyDown(Enum.KeyCode.A) then
		if SidedashReload == true then return end
		side = Enum.KeyCode.A
		SidedashReload = true
	elseif uis:IsKeyDown(Enum.KeyCode.S) then
		if DashReload == true then return end
		side = Enum.KeyCode.S
		DashReload = true
	elseif uis:IsKeyDown(Enum.KeyCode.W) then
		if DashReload == true then return end
		DashReload = true
	end
	task.wait()
	DashHolder:Dash(character, side)
	if side == Enum.KeyCode.A or side == Enum.KeyCode.D then
		task.delay(2.4, function()
			SidedashReload = false
		end)
	elseif side == Enum.KeyCode.W or side == Enum.KeyCode.S then
		task.delay(5, function()
			DashReload = false
		end)
	end
end

--[INIT]--
uis.InputBegan:Connect(function(input, gpe)
	if gpe then return end
	
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		events.Punch:FireServer()
	elseif input.KeyCode == Enum.KeyCode.F then
		isBlocking = true
		events.Block:FireServer(true)
	elseif input.KeyCode == Enum.KeyCode.Q then
		Dash()
	end
end)

uis.InputEnded:Connect(function(input, gpe)
	if gpe then return end

	if input.KeyCode == Enum.KeyCode.F then
		isBlocking = false
		events.Block:FireServer(false)
	end
end)

character:GetAttributeChangedSignal("Blocking"):Connect(function()
	if character:GetAttribute("Blocking") == true then
		animation:Play()
	else
		animation:Stop()
	end
end)
5 Likes

Does it work if so then it’s good :+1: functionally over style it looks fine. It’s not really the style I write code but I don’t see any big hiccups or lag causers in the code

4 Likes

BodyVelocity is deprecated instead use LinearVelocity

i know but he has some bad stuffs like u are not falling when using a dash :frowning:

Looked at the client script, you have a lot of code within the if statements that is the same in all of them. I’d recommend removing those out of the if statement as it would overall reduce the amount of code you have (cleaning it up a bunch in the process)

There’s also redundant variables like playing, which you can just remove and disconnect the connection directly after the slide is done.

So theoretically, something like this should be able to replace those if statements which will cut down on the total amount of code.

		humanoid.WalkSpeed = 0
		local Attachment = Instance.new("Attachment", rootpart)
		local BV = Instance.new("BodyVelocity", Attachment)

		if dashanim == "Front" and sidedashplaying then return end
		if (dashanim == "Front" or dashanim == "Down") and dashreload then humanoid.WalkSpeed = 21; Attachment:Destroy(); dashanimationTrack:Stop() return end
		if (dashanim == "Left" or dashanim == "Right") and sidedashreload then humanoid.WalkSpeed = 21 Attachment:Destroy() dashanimationTrack:Stop() return end

		if (dashanim == "Front" or dashanim == "Down") then
			dashreload = true
		else
			sidedashreload = true
		end
		BV.MaxForce = Vector3.new(math.huge,0,math.huge)
		BV.P = dashanim == "Front" and 9e9 or 8e8
		BV.Parent = rootpart

		local connection = RunService.Heartbeat:Connect(function()
			if dashanim == "Front" then
				BV.Velocity = rootpart.CFrame.RightVector * 1 * 65
			elseif dashanim == "Left" then
				BV.Velocity = rootpart.CFrame.LookVector * (rootpart.CFrame.RightVector * -1) * 65
			elseif dashanim == "Right" then
				BV.Velocity = rootpart.CFrame.RightVector * 1 * 65
			elseif dashanim == "Down" then
				BV.Velocity = rootpart.CFrame.LookVector * -1 * 55
			end
		end)

		dashanimationTrack:Play()
		task.wait(0.3)
		BV:Destroy()
		Attachment:Destroy()
		sidedashplaying = false
		humanoid.WalkSpeed = 21
		connection:Disconnect()
		wait(3)
		if sidedashreload ~= false then
			sidedashreload = false
		end
		if (dashanim == "Front" or dashanim == "Down") then
			dashreload = false
		end
1 Like

Just a random question… Why is there a hitbox thingy for the dash script for damaging? I originally thought it was a thing where if a player dashes onto a wall it’ll cancel their dash but it seems to damage other humanoids. Also, should use a better hit detector for example like the one I had

Well, I’d not use .Touched for my hitboxes, I’d use :GetPartBoundsInBox() instead.

1 Like

just dash like the strongest battlegrounds. Its a reason.

The dash in strongest doesn’t use hitbox. Especially one that damages people.

Actually, he is using it for damage, stun and animation.

Just because it’s deprecated doesn’t mean it’s bad, I’ve used it for a while and never had issues with it, even after loading old games, it worked, and worked really good might I add.

1 Like

UPDATED! v2.0
is this version being good?

-[MODULE]-

local module = {}
local antidebounce = false
local runservice = game:GetService("RunService")
local camera = workspace.CurrentCamera

function module:Dash(character, side)
	local rootpart = character:FindFirstChild("HumanoidRootPart")
	local humanoid = character:FindFirstChild("Humanoid")
	local oldwalkspeed = humanoid.WalkSpeed
	local oldjumppower = humanoid.JumpPower
	humanoid.WalkSpeed = 0
	humanoid.JumpPower = 0
	if not rootpart or not humanoid then return end
	local attachment = Instance.new("Attachment", rootpart)
	local velocity = Instance.new("BodyVelocity", attachment)
	velocity.Name = "Dash"
	velocity.MaxForce = Vector3.new(math.huge,0,math.huge)
	velocity.P = 9e9
	velocity.Parent = rootpart
	local animation
	local connection = runservice.Heartbeat:Connect(function(dt)
		if side == Enum.KeyCode.W then
			animation = humanoid:LoadAnimation(game.ReplicatedStorage.Container.CombatAction.Dash.FrontDash)
			for i=50,0,-1 do
				velocity.Velocity = rootpart.CFrame.LookVector * 1 * i
				task.wait()
			end
		elseif side == Enum.KeyCode.S then
			animation = humanoid:LoadAnimation(game.ReplicatedStorage.Container.CombatAction.Dash.BackDash)
			for i=50,0,-1 do
				velocity.Velocity = rootpart.CFrame.LookVector * -1 * 55
				task.wait()
			end
		elseif side == Enum.KeyCode.A then
			animation = humanoid:LoadAnimation(game.ReplicatedStorage.Container.CombatAction.Dash.LeftDash)
			for i=50,0,-1 do
				velocity.Velocity = camera.CFrame.LookVector:Cross(camera.CFrame.UpVector) * -1 * 55
				task.wait()
			end
		elseif side == Enum.KeyCode.D then
			animation = humanoid:LoadAnimation(game.ReplicatedStorage.Container.CombatAction.Dash.RightDash)
			for i=50,0,-1 do
				velocity.Velocity = camera.CFrame.LookVector:Cross(camera.CFrame.UpVector) * 1 * 55
				task.wait()
			end
		end
	end)
	repeat wait() until animation ~= nil
	animation:Play()
	task.wait(0.5)
	attachment:Destroy()
	connection:Disconnect()
	velocity:Destroy()
	humanoid.WalkSpeed = 16
	humanoid.JumpPower = 7.2
end

return module

-[CLIENT]-

--[SERVICES]--
local uis = game:GetService("UserInputService")

--[ATTRIBUTES]--
local plr = game.Players.LocalPlayer
local character = plr.Character 
local events = game.ReplicatedStorage.Container.Combat.Events
local humanoid = character:FindFirstChild("Humanoid")
local animator = humanoid:FindFirstChild("Animator")
local animation = animator:LoadAnimation(game.ReplicatedStorage.Container.Combat.Animations.Blocking)
local DashHolder = require(game.ReplicatedStorage.Modules.CombatSystem.Dash)

--[VALUES]--
local SidedashReload = false
local DashReload = false
local isBlocking = false

--[FUNCTIONS]--
local function Dash()
	local side = Enum.KeyCode.W
	if uis:IsKeyDown(Enum.KeyCode.D) then
		if SidedashReload == true then return end
		side = Enum.KeyCode.D
		SidedashReload = true
	elseif uis:IsKeyDown(Enum.KeyCode.A) then
		if SidedashReload == true then return end
		side = Enum.KeyCode.A
		SidedashReload = true
	elseif uis:IsKeyDown(Enum.KeyCode.S) then
		if DashReload == true then return end
		side = Enum.KeyCode.S
		DashReload = true
	elseif uis:IsKeyDown(Enum.KeyCode.W) then
		if DashReload == true then return end
		DashReload = true
	end
	task.wait()
	DashHolder:Dash(character, side)
	if side == Enum.KeyCode.A or side == Enum.KeyCode.D then
		task.delay(2.4, function()
			SidedashReload = false
		end)
	elseif side == Enum.KeyCode.W or side == Enum.KeyCode.S then
		task.delay(5, function()
			DashReload = false
		end)
	end
end

--[INIT]--
uis.InputBegan:Connect(function(input, gpe)
	if gpe then return end
	
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		events.Punch:FireServer()
	elseif input.KeyCode == Enum.KeyCode.F then
		isBlocking = true
		events.Block:FireServer(true)
	elseif input.KeyCode == Enum.KeyCode.Q then
		Dash()
	end
end)

uis.InputEnded:Connect(function(input, gpe)
	if gpe then return end

	if input.KeyCode == Enum.KeyCode.F then
		isBlocking = false
		events.Block:FireServer(false)
	end
end)

character:GetAttributeChangedSignal("Blocking"):Connect(function()
	if character:GetAttribute("Blocking") == true then
		animation:Play()
	else
		animation:Stop()
	end
end)

Still no server side. will make a server sided soon

1 Like

There is a easy fix for that by just changing the maxforce mode