Hi. Knockbacks in my combat system are VERY delayed and I am looking for a way to fix it. The knockback is in hitdetection function which is in a module that is called by a serverscript.
local function hitFunc(enemyChar, moveTag)
enemyChar.HumanoidRootPart:SetNetworkOwner(player)
local eHum = enemyChar:FindFirstChild("Humanoid")
if not eHum then return end
if CS:HasTag(enemyChar, moveTag) then return end
if not CS:HasTag(enemyChar, "Parry") and not CS:HasTag(enemyChar, "iFrame") and not CS:HasTag(enemyChar, "Blocking") then
local ePlayer = PLR:GetPlayerFromCharacter(enemyChar)
if ePlayer then
local enemyVariables = ePlayer:WaitForChild("combatVariables")
local eBlockHealth = enemyVariables:WaitForChild("blockHealth")
local eStunned = enemyVariables:WaitForChild("Stunned")
CS:AddTag(enemyChar, moveTag)
task.delay(.1, function()
CS:RemoveTag(enemyChar, moveTag)
end)
local lookDirection = player.Character.HumanoidRootPart.CFrame.LookVector
local bv = Instance.new("BodyVelocity", enemyChar.PrimaryPart)
bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
bv.P = 2400
bv.Velocity = lookDirection * 85 * (196.2/workspace.Gravity) -- Scales with gravity
bv.Name = "RagdollKnockback"
game.Debris:AddItem(bv, 0.2)
eStunned.Value = true
task.delay(2, function()
if eStunned.Value then
eStunned.Value = false
end
end)
eHum:TakeDamage(damage)
--eStunned.Value = true
task.delay(2, function()
--if eStunned.Value then
--eStunned.Value = false
--end
end)
local hitVFX = RS:WaitForChild("VFX"):WaitForChild("General"):WaitForChild("Heavy").Attachment:Clone()
hitVFX.Parent = enemyChar:WaitForChild("Torso"):WaitForChild("TorsoVFXAttachment")
for i, v in pairs(hitVFX:GetChildren()) do
if v:IsA("ParticleEmitter") then
v:Emit(10)
end
end
task.delay(.5, function()
hitVFX:Destroy()
end)
enemyChar.HumanoidRootPart:SetNetworkOwnershipAuto()
Here is the part where knockback is applied. I tried getting into SetNetworkOwnership thing but it doesn’t seem to create any difference here. Do you guys have any recommendations?