Delay on knockbacks

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?

u got task.delay 2s everywhere i would add print commads to find the problem

Delete the enemyChar.HumanoidRootPart:SetNetworkOwnershipAuto() part and it should work
and I would recommend changing this local bv = Instance.new("BodyVelocity", enemyChar.PrimaryPart) into local bv = Instance.new("BodyVelocity") bv.Parent = enemyChar.PrimaryPart

use client scripts for velocity.
simply setting the network ownership to a player allows them to use velocity on the npc
so i’d recommend setting network ownership to a player, then firing a remote event with velocity data to the player, then handling the npcs velocity on the players client.

if this is for PvP, then you should use this same logic, except dont control other players ofcourse.
Just fire a remote event for both clients, and they’ll move themselves.

1 Like

I am completely new to network ownership stuff but don’t I need to reset the ownership after the knockback?

Edit: Also when I do as you said it makes the other player’s POV very delayed instead.

Now I am firing an event to all clients to add the knockback. It is better than before, but still delayed.

						local lookDirection = player.Character.HumanoidRootPart.CFrame.LookVector
						kbRemote:FireAllClients(enemyChar, lookDirection)
local RS = game:GetService("ReplicatedStorage")
local remote = RS:WaitForChild("Remotes"):WaitForChild("Knockback")

remote.OnClientEvent:Connect(function(enemyChar, lookDirection)
	
	local bv = Instance.new("BodyVelocity")
	bv.Parent = 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) 
	
end)

local script is under character scripts.

uhh, it shouldnt be all clients. it should only fire to the enemy players client
or the cloesest players client

Also use linearvelocity