Problem with the knockback direction

ApplyImpulse is a good function to use for NPC knockback, but cannot be used on the server’s side to players (it would have to be client sided to work). Though, this could be easily solved with RemoteEvents.

It does work server-side to players though. Try it yourself.

I have tried before, and if you look at the documentation, it also states so.

You can just set the network owner of all parts in that player to the server, apply the impulse, and then set it back.

I just changed my script to make it work with ApplyImpulse.

Alright now it doesn’t knockback at all.

Also I want the NPC or player to rotate on the air with the knockback.

You need to change the power of the impulse if it doesn’t work. It works on my end.

local knockBackPower = 50

local FightUtils = {}

function FightUtils:knockBack(pChar, eChar)
	local pHrp = pChar and pChar:FindFirstChild("HumanoidRootPart")
	local eHrp = eChar and eChar:FindFirstChild("HumanoidRootPart")

	if pHrp and eHrp then
		local networkOwner = eHrp:GetNetworkOwner()
		eHrp:SetNetworkOwner(nil)
		eHrp:ApplyImpulse(pHrp.CFrame.LookVector * knockBackPower)

		task.wait(2)
		eHrp:SetNetworkOwner(networkOwner)
	end
end

return FightUtils

I did.

I meant to increase it. 50 in terms of the lookvector is almost nothing, change it to 2000 or a really high value and see if it moves the character.

Great but I want the player to rotate on the air

Use :ApplyAngularImpulse().

Change your script to this and tell me if it works:

local knockBackPower = 2000

local FightUtils = {}

function FightUtils:knockBack(pChar, eChar)
	local pHrp = pChar and pChar:FindFirstChild("HumanoidRootPart")
	local eHrp = eChar and eChar:FindFirstChild("HumanoidRootPart")

	if pHrp and eHrp then
		local networkOwner = eHrp:GetNetworkOwner()
		eHrp:SetNetworkOwner(nil)
		
		eHrp:ApplyAngularImpulse(Vector3.new(0, 90, 0))
		eHrp:ApplyImpulse(pHrp.CFrame.LookVector * knockBackPower)

		task.wait(2)
		eHrp:SetNetworkOwner(networkOwner)
	end
end

return FightUtils

You will have to experiment with the parameter.

It’s still the same, with no rotational motion.

And I just want to detect the player’s direction so that the opponent could take knockback from there. I feel much comfortable using my old script but the direction is the only thing that bothers me.

Ohh, I thought it just sent the player flying too far. Sorry for the misunderstanding.

Try this:

local FightUtils = {}

function FightUtils:knockBack(pChar, eChar)
	local pHrp = pChar and pChar:FindFirstChild("HumanoidRootPart")
	local eHrp = eChar and eChar:FindFirstChild("HumanoidRootPart")
	
	if pHrp and eHrp then
		local force = Instance.new("BodyVelocity")
		force.MaxForce = Vector3.new(10, 10, 10) * math.huge
		force.Velocity = pHrp.CFrame.LookVector * 2000
		force.Parent = eHrp
					
		task.delay(0.25, function()
			force:Destroy()
		end)
		
		local rot = Instance.new("BodyAngularVelocity")
		rot.AngularVelocity = Vector3.one * math.pi * 2.5
		rot.MaxTorque = Vector3.one * math.huge
		rot.P = 10000
		rot.Parent = eHrp
		
		task.delay(0.25, function()
			rot:Destroy()
		end)
	end
end

return FightUtils
1 Like

Wait now it makes the opponent disappear. I meant the problem is that the direction only hits the opponent from 2 directions. I want the opponent to knockback in the direction the player is facing.

Mine does that. I also fixed the dissapearing problem from lowering the power value.

It shows an error:

1 Like

Hm that’s weird. It works for me. Could you add some prints inside the module and see if it works to a certain point?

Suddenly I printed (“KB”) and it works!