Hey everyone, I’m trying to make a battlegrounds game and I am working on the dashing right now. I want to make it kinda like the Strongest Battlegrounds where it dashes then punches after pressing Q. The dash part of it works, but the punching doesnt every time. It is kind of random. Also the hitbox stays behind instead of infront of the character.
I have tried messing with it a bit but not much has worked.
Local Script:
local UserInputService = game:GetService("UserInputService")
local ServerScriptService = game:GetService("ServerScriptService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local debounce = false
local dashDistance = 20
local dashDuration = 0.2
local dashCooldown = 2
local dashSpeed = dashDistance / dashDuration
local forwardAnimation = script.Dash
local function performDash(direction)
if debounce then return end
debounce = true
local dashVelocity = Vector3.new(0, 0, 0)
if direction == "Forward" then
for i,v in pairs(humanoid:GetPlayingAnimationTracks()) do
v:Stop()
end
local loadedForwardDash = humanoid.Animator:LoadAnimation(forwardAnimation)
loadedForwardDash:Play()
loadedForwardDash:GetMarkerReachedSignal("Dash"):Connect(function()
loadedForwardDash:AdjustSpeed(0)
end)
dashVelocity = character.PrimaryPart.CFrame.LookVector * dashSpeed
wait(.1)
loadedForwardDash:AdjustSpeed(1)
loadedForwardDash:GetMarkerReachedSignal("Punch"):Connect(function()
ReplicatedStorage.Events.DashPunch:FireServer()
end)
elseif direction == "Backward" then
dashVelocity = -character.PrimaryPart.CFrame.LookVector * dashSpeed
elseif direction == "Left" then
dashVelocity = -character.PrimaryPart.CFrame.RightVector * dashSpeed
elseif direction == "Right" then
dashVelocity = character.PrimaryPart.CFrame.RightVector * dashSpeed
end
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.Velocity = dashVelocity
bodyVelocity.MaxForce = Vector3.new(1e5, 0, 1e5)
bodyVelocity.P = 9e4
bodyVelocity.Parent = character.PrimaryPart
wait(dashDuration)
bodyVelocity:Destroy()
wait(dashCooldown)
debounce = false
end
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.KeyCode == Enum.KeyCode.Q then
local direction = "Forward"
if UserInputService:IsKeyDown(Enum.KeyCode.S) then
direction = "Backward"
elseif UserInputService:IsKeyDown(Enum.KeyCode.A) then
direction = "Left"
elseif UserInputService:IsKeyDown(Enum.KeyCode.D) then
direction = "Right"
end
performDash(direction)
end
end)
Server Script:
local AttackHitboxes = require(script.Parent.Services.AttackHitboxes)
game:GetService("ReplicatedStorage").Events.DashPunch.OnServerEvent:Connect(function(Player)
local character = Player.Character
AttackHitboxes.CreateHitboxes(character, Vector3.new(9, 9, 5), 10, true)
end)
The hitbox script is a whole other module script… same one used for the fighting system that I have.
local function performDash(direction)
if debounce then return end
debounce = true
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.MaxForce = Vector3.new(1e5, 0, 1e5)
bodyVelocity.P = 9e4
bodyVelocity.Parent = character.PrimaryPart
local dashVelocity = Vector3.new(0, 0, 0)
bodyVelocity.Velocity = dashVelocity
if direction == "Forward" then
for i,v in pairs(humanoid:GetPlayingAnimationTracks()) do
v:Stop()
end
local loadedForwardDash = humanoid.Animator:LoadAnimation(forwardAnimation)
loadedForwardDash:Play()
loadedForwardDash:GetMarkerReachedSignal("Dash"):Connect(function()
loadedForwardDash:AdjustSpeed(0)
wait(dashTime)
loadedForwardDash:AdjustSpeed(1)
end)
loadedForwardDash:GetMarkerReachedSignal("Punch"):Connect(function()
ReplicatedStorage.Events.DashPunch:FireServer()
bodyVelocity:Destroy()
end)
elseif direction == "Backward" then
dashVelocity = -character.PrimaryPart.CFrame.LookVector * dashSpeed
bodyVelocity.Velocity = dashVelocity
wait(dashTime)
bodyVelocity:Destroy()
elseif direction == "Left" then
dashVelocity = -character.PrimaryPart.CFrame.RightVector * dashSpeed
bodyVelocity.Velocity = dashVelocity
wait(dashTime)
bodyVelocity:Destroy()
elseif direction == "Right" then
dashVelocity = character.PrimaryPart.CFrame.RightVector * dashSpeed
bodyVelocity.Velocity = dashVelocity
wait(dashTime)
bodyVelocity:Destroy()
end
wait(dashCooldown)
debounce = false
end
make the body velocity at the top of the script
If this still doesnt work check that you have published the correct animation with all events, if that also doesnt work use keyframe reached instead of get marker reached signal as it works better.
Sorry, mistake on my part again, you should set dashVelocity at the top of the script to : BodyVelocity.Velocity = character.PrimaryPart.CFrame.LookVector * dashSpeed instead of Vector3.new(0,0,0)
Make sure your punch marker is being triggered you can test that by adding print inside of its function, dont forget to add bodyVelocity:Destroy() inside it as well
I found the problem after some time, it creates 2 bodyVelocitys after clicking Q once and deletes one of the bodyVelocitys, leaving the other one there.