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.
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 …
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.