BodyForce not working

Hi, so I’m trying to make a Knockback system, but for some reason the dummy does not move at all.

local function Knockback()
   if not Character then return end
   local Root = Character:WaitForChild(HumanoidRootPart)
   local Attachment = Instance.new(Attachment, Root)
   game:GetService(Debris):AddItem(Attachment, 0.3)
   local VectorForce = Instance.new(VectorForce, Attachment)
   VectorForce.RelativeTo = Enum.ActuatorRelativeTo.World
   VectorForce.Attachment0 = Attachment
   local Force = (Root.CFrame.LookVector * Config:WaitForChild("KnockbackDistance").Value) + Vector3.new(0,Config:WaitForChild("KnockupDistance").Value,0)
   VectorForce.Force = Force

I don’t know what I’ve done wrong and it’s been approximately 3 hours that i’m stuck with this.
Any help is very appreciated!

Pretty sure you need to use quotes around the instance type, eg.

local Attachment = Instance.new("Attachment", Root)
local VectorForce = Instance.new("VectorForce", Attachment)

I also find it helpful to do nil/print checks anytime I’m setting a variable to verify it is being set and to the right thing

I’d also grab the “KnockbackDIstance” as a local variable at the start and use that in your Force = line, if only to make it more readable but also avoids an extra WaitForChild call.

local kbDistance = Config:WaitForChild("KnockbackDIstance").Value
local Force = (Root.CFrame.LookVector * kbDistance + Vector3.new(0, kbDistance, 0)
2 Likes

VectorForce also considers friction & gravity when being applied, so if the character is on the ground, its gonna be harder to slide them with the friction the default player has; because of this, you would have to have a way larger force applied than what you may think(like 4k). If you want to guarantee the character to be knocked back with a constant force, you might want to try and use LinearVelocity instead.

2 Likes

Common mistake, but you might’ve forgotten to call the function.

1 Like

You also forgot to put quotes around some parts of your code.

1 Like