You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I’m trying to make a knockback system using body velocity.
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.
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
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
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.
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" )
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.