im trying to add knockback to my game but using a attack that causes knockback on a player doesn’t push them back, when i use a attack that causes knockback on a dummy it works fine.
(im using HumanoidRootPart:ApplyImpulse() )
Knockback Against Player
Knockback Against a Dummy
Sever Script:
local character = script.Parent.Parent
local Humanoid = character.Humanoid
local function OnTouched(HitBox)
if HitBox.Name == "HitBox" and HitBox.HitTargetV.Value == false and HitBox.OwnerV.Value ~= character then
HitBox.HitTargetV.Value = true
HitBox.PassedThroughTarget.Value = character
if HitBox.OwnerV.Value.HumanoidRootPart then
local targetPart = HitBox.OwnerV.Value.HumanoidRootPart
local head = character:FindFirstChild("HumanoidRootPart")
local newPosition
if targetPart.CFrame.lookVector.Y == 0 then
newPosition = targetPart.Position + targetPart.CFrame.lookVector
else
newPosition = targetPart.Position + Vector3.new(targetPart.CFrame.lookVector.X, 0, targetPart.CFrame.lookVector.Z)
end
head.Position = newPosition
local directionVector = head.Position - targetPart.Position
directionVector = directionVector.Unit
directionVector = directionVector * 3
newPosition = head.Position + directionVector
head.Position = newPosition
local directionVector = targetPart.Position - head.Position
directionVector = directionVector.Unit
head.CFrame = CFrame.new(head.Position, head.Position + directionVector)
if HitBox.Stuns.StunAnimation.AnimationId ~= "rbxassetid://0" then
local StunAnimation = HitBox.Stuns.StunAnimation
local AnimAnim = AnimationController:LoadAnimation(StunAnimation)
AnimAnim:Play()
end
else
local targetPart = HitBox.Parent.Root
local head = character:FindFirstChild("HumanoidRootPart")
local newPosition
if targetPart.CFrame.lookVector.Y == 0 then
newPosition = targetPart.Position + targetPart.CFrame.lookVector
else
newPosition = targetPart.Position + Vector3.new(targetPart.CFrame.lookVector.X, 0, targetPart.CFrame.lookVector.Z)
end
head.Position = newPosition
local directionVector = head.Position - targetPart.Position
directionVector = directionVector.Unit
directionVector = directionVector * 3
newPosition = head.Position + directionVector
head.Position = newPosition
local directionVector = targetPart.Position - head.Position
directionVector = directionVector.Unit
head.CFrame = CFrame.new(head.Position, head.Position + directionVector)
if HitBox.Stuns.StunAnimation.AnimationId ~= "rbxassetid://0" then
local StunAnimation = HitBox.Stuns.StunAnimation
local AnimAnim = AnimationController:LoadAnimation(StunAnimation)
AnimAnim:Play()
end
end
if HitBox.Knockback.Value == true then
local Distance = HitBox.Knockback.Force.Value
local lookVector = character.HumanoidRootPart.CFrame.LookVector
local force = -lookVector * Distance
character.HumanoidRootPart:ApplyImpulse(force)
if HitBox.Stuns.Value == true then
Stunned.Value = true
wait(HitBox.Stuns)
end
end
end
end
character.Humanoid.Touched:Connect(OnTouched)
this script is applied to both the players and dummys