Awesome module script. You’re going in the right direction with all this, so let’s make some changes.
In your module script, we will create a BodyVelocity every time your character hits the target.
So we will make:
function Knockback.createVelocity()
local bv = Instance.new("BodyVelocity");
bv.P = 1250;
local max = 75000;
bv.MaxForce = Vector3.new(max, max, max);
return bv;
end
So now we have our BodyVelocity. Next, we’ll apply our knockback with the direction that we are looking at:
local Debris = game:GetService("Debris");
function knockback.applyKnockback(hrp, targetHRP, power, duration)
if hrp and targetHRP then
local bv = knockback.createVelocity()
local direction = (hrp.Position - targetHRP.Position).Unit
bv.Velocity = -direction * power
bv.Parent = targetHRP
Debris:AddItem(bv, duration)
end
end
Try this out and see if it works for you.