Ok so, i would say u could easily check if the hrp got a block hitbox, i mean like if hit:FindFirstChild("BlockHitbox") then but i dont understand what is part.Parent ~= "Hitbox" as i said it make no sense to check this as it will always be true
Another thing, to achieve what ur trying to do I would rather put a bool value in the hrp saying if u are blocking or not instead of creating a new block
i dont know how much more performant this solution is, or if it is what you are trying to achieve, but here is a solution i provided for another developer, and the answer i provided is to be placed in the hitbox.touched or whatever you use to detect hit players
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local rootpart = script.Parent.Parent:WaitForChild("HumanoidRootPart")
local animationController = game:GetService("Players").LocalPlayer.Character:WaitForChild("Humanoid"):WaitForChild("Animator")
local UIS = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
--dash
local dashevent = game:GetService("ReplicatedStorage").Events.Dash
local animation = Instance.new("Animation")
local mymodule = require(game.ReplicatedStorage.Modules.Ragdoll)
--end
local animations = {
["DashFront"] = "rbxassetid://16566527703";
["DashLeft"] = "rbxassetid://16591663577";
["DashRight"] = "rbxassetid://16596178032";
["DashDown"] = "rbxassetid://16613175493";
}
local dashreload = false
local sidedashreload = false
local sidedashplaying = false
local evasive = true
UIS.InputBegan:Connect(function(key, typing)
local humanoid = char:WaitForChild("Humanoid")
if humanoid.WalkSpeed == 0 or humanoid.WalkSpeed == 2 then return end
local dashanim = "Front"
if typing then return end
if key.KeyCode == Enum.KeyCode.Q then
local DHold = UIS:IsKeyDown(Enum.KeyCode.D)
local WHold = UIS:IsKeyDown(Enum.KeyCode.W)
local SHeld = UIS:IsKeyDown(Enum.KeyCode.S)
local AHeld = UIS:IsKeyDown(Enum.KeyCode.A)
if WHold == true then
dashanim = "Front"
end
if AHeld == true then
dashanim = "Left"
end
if DHold == true then
dashanim = "Right"
end
if SHeld == true then
dashanim = "Down"
end
animation.AnimationId = animations["Dash"..dashanim]
local dashanimationTrack = animationController:LoadAnimation(animation)
humanoid.WalkSpeed = 0
local Attachment = Instance.new("Attachment", rootpart)
local BV = Instance.new("BodyVelocity", Attachment)
if dashanim == "Front" then
if sidedashplaying == true then return end
if dashreload == true then humanoid.WalkSpeed = 21; Attachment:Destroy(); dashanimationTrack:Stop() return end
local playing = false
dashreload = true
BV.MaxForce = Vector3.new(math.huge,0,math.huge)
BV.P = 9e9
BV.Parent = rootpart
playing = true
local function velocity()
local connection
connection = RunService.Heartbeat:Connect(function()
BV.Velocity = rootpart.CFrame.LookVector * 1 * 60
if not playing then
connection:Disconnect()
end
end)
end
velocity()
task.wait(0.01)
dashanimationTrack:Play()
dashevent:FireServer(player)
dashevent.OnClientEvent:Connect(function(player, results)
BV:Destroy()
playing = false
Attachment:Destroy()
humanoid.WalkSpeed = 21
wait(5.5)
dashreload = false
end)
elseif dashanim == "Left" then
local ragdollvalue = char:WaitForChild("RagdollValue")
local needtounragdoll = false
if ragdollvalue == true and evasive then
needtounragdoll = true
elseif ragdollvalue == false then
needtounragdoll = false
end
local playing = false
sidedashplaying = true
if sidedashreload == true then humanoid.WalkSpeed = 21 Attachment:Destroy() dashanimationTrack:Stop() return end
if needtounragdoll then
mymodule:unragdoll(char)
evasive = false
wait(30)
evasive = true
end
sidedashreload = true
BV.MaxForce = Vector3.new(math.huge,0,math.huge)
BV.P = 8e8
BV.Parent = rootpart
playing = true
local function velocity()
local connection
connection = RunService.Heartbeat:Connect(function()
BV.Velocity = rootpart.CFrame.RightVector * -1 * 70
if not playing then
connection:Disconnect()
end
end)
end
velocity()
dashanimationTrack:Play()
task.wait(0.3)
BV:Destroy()
Attachment:Destroy()
sidedashplaying = false
humanoid.WalkSpeed = 21
wait(3)
if sidedashreload ~= false then
sidedashreload = false
end
elseif dashanim == "Right" then
local ragdollvalue = char:WaitForChild("RagdollValue")
local needtounragdoll = false
if ragdollvalue == true and evasive then
needtounragdoll = true
elseif ragdollvalue == false then
needtounragdoll = false
end
sidedashplaying = true
local playing = false
if sidedashreload == true then humanoid.WalkSpeed = 21 Attachment:Destroy() dashanimationTrack:Stop() return end
if needtounragdoll then
mymodule:unragdoll(char)
evasive = false
wait(30)
evasive = true
end
sidedashreload = true
BV.MaxForce = Vector3.new(math.huge,0,math.huge)
BV.P = 8e8
BV.Parent = rootpart
playing = true
local function velocity()
local connection
connection = RunService.Heartbeat:Connect(function()
BV.Velocity = rootpart.CFrame.RightVector * 1 * 70
if not playing then
connection:Disconnect()
end
end)
end
velocity()
dashanimationTrack:Play()
task.wait(0.3)
playing = false
BV:Destroy()
Attachment:Destroy()
sidedashplaying = false
humanoid.WalkSpeed = 21
wait(3)
if sidedashreload ~= false then
sidedashreload = false
end
elseif dashanim == "Down" then
local playing = false
if dashreload == true then Attachment:Destroy() humanoid.WalkSpeed = 21 dashanimationTrack:Stop() return end
dashreload = true
BV.MaxForce = Vector3.new(math.huge,0,math.huge)
BV.P = 8e8
BV.Parent = rootpart
playing = true
local function velocity()
local connection
connection = RunService.Heartbeat:Connect(function()
BV.Velocity = rootpart.CFrame.LookVector * -1 * 60
if not playing then
connection:Disconnect()
end
end)
end
velocity()
dashanimationTrack:Play()
task.wait(0.3)
playing = false
BV:Destroy()
Attachment:Destroy()
humanoid.WalkSpeed = 21
wait(3)
if sidedashreload ~= false then
sidedashreload = false
end
dashreload = false
end
end
end)
server with your way:
local dashevent = game:GetService("ReplicatedStorage").Events.Dash
local stun = require(game.ServerStorage.Module.StunHandlerV2)
local player = game.Players.LocalPlayer
--end
local hitanimations = {
["Dash1"] = game.ReplicatedStorage["Hitted combo"].Dash1;
}
dashevent.OnServerEvent:Connect(function(player)
local char = player.Character or player.CharacterAdded:Wait()
local rootpart = char:WaitForChild("HumanoidRootPart")
local hitbox = Instance.new("Part")
hitbox.Size = Vector3.new(3,3,1.5)
hitbox.Parent = rootpart
hitbox.CanCollide = false
hitbox.CFrame = rootpart.CFrame + (rootpart.CFrame.lookVector * 1.1)
hitbox.Transparency = 0
local weld = Instance.new("WeldConstraint", hitbox)
weld.Part0 = hitbox
weld.Part1 = hitbox.Parent
hitbox.Name = "Hitbox"
local humanoid = char:WaitForChild("Humanoid")
local results = nil
local checkcorrect = false
local blockresults = "bad"
local function attack(enemy)
hitbox.CanTouch = false
local numberhit = 1
local enehum = enemy.Parent:WaitForChild("Humanoid")
local animator = enehum.Animator
local animation = hitanimations["Dash"..numberhit]
local dashanimationTrack = animator:LoadAnimation(animation)
if animator then
dashanimationTrack:Play()
end
enehum:TakeDamage(5)
stun.Stun(enehum, 2)
end
local debounced = false
local function check()
if hitbox.CanTouch == false then return end
hitbox.Touched:Once(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
debounced = true
dashevent:FireClient(player, results)
local enemy = hit.Parent:FindFirstChild("HumanoidRootPart")
if hit.Parent:WaitForChild("Block").Value == true then
local ObjectSpace = rootpart.CFrame:inverse() * enemy.CFrame
if ObjectSpace.Z < 0 then
return
else
attack(enemy)
end
else
attack(enemy)
end
end
end)
end
repeat check() until hitbox.CanTouch == true or results == true
task.wait(0.6)
results = false
if results == false and checkcorrect ~= true then
dashevent:FireClient(player, results)
end
hitbox:Destroy()
humanoid.WalkSpeed = 21
end)
you seems to not understand how functions work i mean in ur local script u are doing this :
local function velocity()
local connection
connection = RunService.Heartbeat:Connect(function()
BV.Velocity = rootpart.CFrame.LookVector * 1 * 60
if not playing then
connection:Disconnect()
end
end)
end
velocity()
but it is the same as doing this :
local connection
connection = RunService.Heartbeat:Connect(function()
BV.Velocity = rootpart.CFrame.LookVector * 1 * 60
if not playing then
connection:Disconnect()
end
end)
So in ur case its the velocity function, u can just define it with params :
local function velocity(x, y)
local connection
connection = RunService.Heartbeat:Connect(function()
BV.Velocity = rootpart.CFrame.LookVector * x * y
if not playing then
connection:Disconnect()
end
end)
end
velocity(-1, 60)
else the script seems veryyyy hugge and so i cant understand everything as theres no comment, i read the entire thing and it seems not optimized at all, i dont really know what u want to achieve with all that but consider creating module script for functions and creating multiples script for each systems cuz it make ur script unreadable