Issues with body velocity not being applied

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I’m trying to make a knockback system using body velocity.
  2. What is the issue? Include screenshots / videos if possible!

Body velocity gets applied with a script but doesn’t work for some reason. The issue seems to fix itself when I cut the body velocity and then paste it back.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I couldn’t find anything related to the topic on the dev forum. In terms of solutions, I’ve tried giving the target body velocity with just the default settings but no changes either.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

function Helpful.PlayerBasedKnockback(target,char,knockbackSpeed,knockbackY,multiplier)
	if not CollectionService:HasTag(target,"Blocking") then
		local RootCFrame = char.PrimaryPart.CFrame
		local hitCFrame = target.PrimaryPart.CFrame
		local targetRoot = target.PrimaryPart
		local endCF  = hitCFrame + RootCFrame.lookVector * multiplier + hitCFrame.upVector * knockbackY
		local newCF = CFrame.new(hitCFrame.Position,(endCF).Position)
		
		local bv = Instance.new("BodyVelocity")
		bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
		bv.Velocity = newCF.LookVector * 50
		bv.Parent = targetRoot
	end
end

Any help would be appreciated, thanks in advance!

Hmm, seems like you are applying the body velocity changes locally, instead of on the server like when you paste it back into the presumably server owned NPC.

if that was the case the BodyVelocity instance wouldn’t have appeared in the server view, the behavior OP is experiencing seems to be very similar to velocity being overlapped, where the new BodyVelocity was added while the humanoidrootpart is being affected by a different body mover, causing the newest velocity to be cancelled even if the first is removed afterward

1 Like

Yeah like RoyalTHEUSERNAME said, it wouldn’t appear in the server view if that was the case. The body velocity is being applied with a server script, but it’s just not working for some reason.

Hmm, I saw when you repasted the body velocity there was this print statement:

it took 13.666 amount of time

Any more information on the things that might affect players movement it your script?

This was part of a function to see how long it took to reach the destination with body velocity. I removed it in an edit because it wasn’t relevant to the script,

Here’s the code for it:

local timed = tick()
while RunService.Heartbeat:Wait() do
	if (targetRoot.CFrame.Position - endCF.Position).Magnitude <= 5 then
	      break
	end
end
print("It took ".. tick() - timed .. " amount of time"  )

Can you test to see if the BodyVelocity is applied when you make the humanoid jump?

Nope

You know you can’t really do much velocity with just 23.372, 4.975, -43.92.

You’re gonna want it to be like 8,000.

Yeah but that’s not the issue, the problem is the body velocity just isn’t working until I cut it then paste it back.

Possibly it’s the humanoid resisting the force like how you get pushed but still stand up, try enabling the physics option for the humanoid.

Alright, I figured out the issue. My combat system moves whoever gets hit slightly backward with body velocity, and then if it’s the last hit it calls the function in the module to knock them back. This causes the body velocity added by the knockback function to be overridden by the one that pushes them back slightly, causing it not to work. When I cut the body velocity and pasted it back, the old one had already been deleted so it then works.

Thanks to everyone who helped, I appreciate it a lot.

3 Likes