KnockBack System

Currently trying to make a Knockback system for a bat tool, but the dummy won’t move at all. Here is the code:

function module.Knockback(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local char = hit.Parent
		local HRP = char:FindFirstChild("HumanoidRootPart")
		
		if HRP then
			local Speed = 100
            local TotalForce = 80000

			local KnockBack = Instance.new("BodyVelocity")
			KnockBack.Parent = HRP --part is the target of the knockback/ the opponent

			KnockBack.MaxForce = Vector3.new(TotalForce,TotalForce,TotalForce)
			KnockBack.Velocity = char:FindFirstChild("HumanoidRootPart").CFrame.LookVector *- Speed
			task.wait(0.3)
			KnockBack:Destroy()
		end
	end
end
1 Like

Check if anything’s anchored on the dummy.

1 Like

no nothing is anchored (Emtpy space)

Try changing the maxforce and P of the body velocity

KnockBack.MaxForce =  Vector3.new(100000,100000,100000)
KnockBack.P = 1500

edit: nvm you did change the maxforce

Use

HumanoidRootPart:ApplyImpulse(VECTOR3)

I got it to work with the anchor thing, thanks. Another problem though, when I throw the player, its very buggy and only throws the play in 1 position.

So you would need your own character’s humanoidrootpart lookvector
To do so, find your character somehow in workspace and find its HRP lookvector.
So the direction your character faces is the knockback direction.

Nvm… I’ve modified it, but the player will just go up and down and doesn’t move in any direction

function module.Knockback(plr_who_swung, hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local char = hit.Parent
		local HRP = char:FindFirstChild("HumanoidRootPart")
		
		if HRP then
			local lv = plr_who_swung.Character.HumanoidRootPart.CFrame.LookVector
			
			local Speed = 100
			local TotalForce = 80000

			local KnockBack = Instance.new("BodyVelocity")
			KnockBack.Parent = HRP

			KnockBack.MaxForce = Vector3.new(TotalForce, TotalForce, TotalForce)
			KnockBack.Velocity = char:FindFirstChild("HumanoidRootPart").CFrame.LookVector * lv
			HRP.Position += Vector3.new(0, 2, 0)
			
			task.wait(0.2)
			KnockBack:Destroy()
		end
	end
end
local lv = plr_who_swung.Character.HumanoidRootPart.CFrame.LookVector
local LV = char:FindFirstChild("HumanoidRootPart").CFrame.LookVector * lv 
local Speed = 100
HRP.Position += Vector3.new(0, 2, 0)
HRP:ApplyImpulse(LV *Speed)

Try this

Again the same problem, the player doesn’t move whatsoever. Here is the full code I used:

function module.Knockback(plr_who_swung, hit, part)
	if hit.Parent:FindFirstChild("Humanoid") then
		local char = hit.Parent
		local HRP = char:FindFirstChild("HumanoidRootPart")
		
		if HRP then 
			local lv = plr_who_swung.Character.HumanoidRootPart.CFrame.LookVector
			local LV = char:FindFirstChild("HumanoidRootPart").CFrame.LookVector * lv 
			
			local Speed = 100
			
			HRP:ApplyImpulse(LV*Speed)
		end
	end
end
function module.Knockback(plr_who_swung, hit, part)
	if hit.Parent:FindFirstChild("Humanoid") then
		local char = hit.Parent
		local HRP = char:FindFirstChild("HumanoidRootPart")
		
		if HRP then 
			local lv = plr_who_swung.Character.HumanoidRootPart.CFrame.LookVector
			local LV = char:FindFirstChild("HumanoidRootPart").CFrame.LookVector * lv 
			
			local Speed = 100
			HRP:SetNetworkOwner(nil)
			HRP:ApplyImpulse(LV*Speed)
task.wait(3)
HRP:SetNetworkOwner(game.Players:GetPlayerFromCharacter(HRP.Parent)
		end
	end
end

Have to set network owner to nil otherwise server has no control over client

Same thing, the player does not move whatsoever

Try firing a remoteevent to send the client the Vector3 value for the “ApplyImpulse” then use the apply impulse through the client side. I understand that this could be exploited, but you may be able to come up with a way to stop this?

I don’t think this idea is very plausible. Sending a remote event to the client would be kinda dumb since only that client would be able to see the player moving. I want the entire force system / damage system to be fully server sided, so no exploits can be made.

Oh my bad, i thought it was a real player getting knocked back.

It is (empty space blalalalala)

I will do some tests to see if i can get this to work


		local Speed = 70000 
		
		HRP:SetNetworkOwner(nil)
		
		local vF = Instance.new("VectorForce")
		vF.RelativeTo ="Attachment0"
		vF.Attachment0 = HRP:FindFirstChildWhichIsA("Attachment")
		vF.ApplyAtCenterOfMass = true
		vF.Force = LV*Speed
		vF.Parent = HRP
		
		wait(.15)
		
		vF:Destroy()
		HRP:SetNetworkOwner(plr)

the speed was too little to move the player