How can I add knockback to a weapon?

Hello! I’ve recently had a goofy game idea, hit people with a baseball bat and send them flying. I know how to script tools and such but I have no idea how to add knockback to it. I would appreciate any help on the matter.
Thank you in advance

You would add a body velocity in the opposite direction of the player.

and how would I do that? I have no idea how to work with BodyVelocity, which is why i asked for help in the first place

1 Like

Watch this video, Alvin makes a tool that launches things and people back.

While this gives me a vague idea of how the whole thing works, what I want to accomplish is make the player get sent flying not horizontally but in a diagonal-forwards way if that makes sense.

Do you mean up? If you look at the values, you can change the way the force pushes you.

Yes, I meant up. But thank you for clearing that up, I’ll rewatch the video and see what I can do

On the code for the server you could do this.

So in the video the velocity is 100 times the negative of the lookVector of the player thats targeted. We could remove that and turn it into this:

A Vector3 works off of Vector3.new(X, Y, Z) so we can change it from lookVector to just a normal vector3

We want to go up so we change the Y

So we could change line 5


to

PushForce.Velocity = Vector3.new(0, 100, 0)

You can change the middle number(Y) to what ever you want.

3 Likes

I figured it out. Thank you for the help!

1 Like

Hey, small update on the situation:

it didn’t work at all

when I implemented the scripts and stuff into my own tool, nothing worked. The players aren’t being flung. Is there any way to fix it?

Any errors? Did you make sure to make a remote event so that the server can fling?

local baseball at = --where the tool is here

for i, v in pairs(game.Players:GetPlayers()) do
v.Touched:Connect(function(hit)
if hit.Name = baseballbat then
--code here

I just made my own tool. I got it working. If you need help here is the model to the tool that flings players and anything with a humanoid.
https://www.roblox.com/library/6655542222/BlasterTool

i’ll look into your tool, i will edit this post if i get the results wanted. thanks in advance

update on the situation:

it does not work at all

i used your tool as a sample, but none of it worked in studio at all. i even tested it in a studio 2 player server but to no avail.

Thats so weird. It works great for me

it is weird. i’ve tried everything i could to make it work with both my and your tool but none of it would work.

Are you sure you have the tool in your backpack? you need put it in StarterPack and then select the tool then click on who u want to launch.

i have the tool in starterpack, however i don’t want to fling the person upon clicking them, I want my baseball bat to hit them and THEN send them flying.

Its a example of how it could launch the person you hit.