Knockback isnt working?

the sword isnt doing kb but it is damaging the enemy?

Enemy.Humanoid:TakeDamage(20)
					
local dir = (Enemy.HumanoidRootPart.Position - Player.HumanoidRootPart.Position).Unit
local att = Instance.new("Attachment",   Enemy.HumanoidRootPart)
local force = Instance.new("VectorForce", Enemy.HumanoidRootPart)
print(Player)
print(Enemy)
        if Player.HumanoidRootPart and Enemy.HumanoidRootPart then
        force.Attachment0 = att
        force.Force = (dir + Vector3.new(0,1,0)).Unity * 50
        force.RelativeTo = Enum.ActuatorRelativeTo.World
        Enemy.Humanoid.PlatformStand = false
        print("RAN")
end

Some old pushback test scripts … maybe this will help.
Or possibly give you a different approach at a pushback.
One is a module version placed inside the sword script.
One is a touch version placed in a part …
A task.wait() will not work in this case.

Touch
-- SeverScript

local bv, char
local db = true
script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") ~= nil then
		if db then db = false char = hit.Parent
			bv = Instance.new("BodyVelocity")
			bv.Parent = (char.Head)
			bv.MaxForce = Vector3.new(100000,100000,100000)
			bv.Velocity = (char.Head.CFrame.LookVector * -80)
				+ (char.Head.CFrame.UpVector * 80)
			wait(0.01) bv:Destroy()
			db = true
		end
	end
end)
Module
-- ModuleScript

local bv, char
local db = true
local module = {}
function module.PushBack(hit)
	if hit.Parent:FindFirstChild("Humanoid") ~= nil then
		if db then db = false char = hit.Parent
			bv = Instance.new("BodyVelocity")
			bv.Parent = (char.Head)
			bv.MaxForce = Vector3.new(100000,100000,100000)
			bv.Velocity = (char.Head.CFrame.LookVector * -80)
				+ (char.Head.CFrame.UpVector * 80)
			wait(0.01) bv:Destroy()
			db = true
		end
	end
end
return module

-- needed in the sword script ...
-- local pb = require(script.PushBack) <-- this script named PushBack inside the sword script
-- pb.PushBack(Hit)                    <-- call from the sword script

These scripts take into account the direction the hit is facing.

1 Like

what is char set to, local player character or enemy character?

1 Like

That would be hit.parent … so enemy. More so enemy’s character listing.
The way you’re seeing it, is as a set up as a nil for char later use in the script.
Could have been written as …

if db then db = false 
  local char = hit.Parent

i have tried this but i cant seem to ballence the kb, it feels unresponsive

local bv = Instance.new("BodyVelocity")
					bv.Parent = (Enemy.HumanoidRootPart)
					bv.MaxForce = Vector3.new(1,1,1) * 100000
					bv.Velocity = (Vector3.new(Player.Character.Head.CFrame.LookVector.X, 0.45, Player.Character.Head.CFrame.LookVector.Z) * 60)
					wait(0.05) 
					bv:Destroy()

(the sword attacks fast (5 times a second) and i dont know how to adjust it to make it feel right, im going for roblox bedwars esc knockback

1 Like

bv.Velocity = (char.Head.CFrame.LookVector * -80) +(char.Head.CFrame.UpVector * 80)
The 80’s should be the same. -60,60 -40,40 and you can lower the 100000 a bit.
Will have to play with the numbers to find your sweet spot.

100000 overall power, -80 distance back, 80 distance up
Keep the last two numbers the same for a smooth arc. As in -80,80 -60,60 -40,40

This could be any part also, not just the head. (any facing part)

I’ve never used this for a weapon …
I just know it will figure the angle by the angle of the player that hit it.

If you tired the touch version on a block. You can see it don’t matter what angle they touch it from.
It will always push back at the right angle to be a push-back.

1 Like