Why is my knockback not working?

  1. What do you want to achieve? Keep it simple and clear!
    I want to make a custom bomb that knockbacks humanoids
  2. What is the issue? Include screenshots / videos if possible!
    The knockback aint knocking back and i want to know why
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have, just found things about direction
    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!
local ball=script.Parent
task.wait(2)
ball.Anchored=true
ball.CanCollide=false
for count = 1,10 do

	ball.Size=Vector3.one*1.25
	task.wait(0.5/count)
	ball.Size=Vector3.one*2
	task.wait(0.5/count)
end
ball.Size=Vector3.one*10

ball.Touched:Connect(function(hit)

	assert(hit.Parent:FindFirstChild('Humanoid') or hit:FindFirstChild('Humanoid'),'hehee')
	
	local direction : Vector3 = -(ball.Position - hit.Parent.PrimaryPart.Position).Unit
	hit.Parent.Humanoid:TakeDamage(3)
	print(hit.Parent)
	
	hit.Parent.HumanoidRootPart:ApplyImpulse(direction*1000)
end)
task.wait(0.3)
ball:Destroy()

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

Any errors in your output window?
Have you tried increasing the impulse Force? How about making the force upwards slightly to get past any friction between the player and the floor.

Put prints in your script to find out what’s working and if it’s getting stuck and why.

Something like after the ball.Touched function put something like print(hit) to see what it hit.

Also I know I’ve seen a lot of posts about knockbacks from punches or spells. Have you tried different search wording? I just searched ‘knockback’ and found quite a few posts about that, but maybe try ‘pushback’ or ‘push player’.

Replace:

hit.Parent.HumanoidRootPart:ApplyImpulse(direction*1000)

with

task.delay(0, function()
	hit.Parent.HumanoidRootPart.AssemblyLinearVelocity = direction*1000
end)

For some reason, it needs to have a task.delay, and no task.spawn wont work either. See if this works for you.
knockback

2 Likes

hey there! I know that everything works except for the applyimpulse part! even if I set it to absurd numbers nothing happens. it is like the applyimpulse isnt there. When I do the apply impulse command in the command bar while the game is running , it works, but in the script it doesnt

hey there, thanks for the help! If you don’t mind, could you tell me why the apply impulse code wasn’t doing anything? I am very curious about it

From a bit of experimentation, it seems like Applying an impulse on a Player’s Character only works for local scripts.

Its hard to get a character to move with realistic physics just because of the humanoid being a pain. There are a few humanoid states (like sitting, platform standing, etc) that enable physics on the character to be more accurate so I recommend looking into that.

As for ApplyImpulse I have no clue why that wouldn’t work, so I experiment with other options.

1 Like

that would be strange as the documentation for apply impulse says:" If the part is owned by the server, this function must be called on a server Script. If the part is owned by a client, this function can be called on a LocalScript or server Script." and i was using a server script.

So, I think the character is controlled and owned by the client. You can still use like LinearVelocity on the server-side to move the character back.

Correct; the character parts are owned by the user. Look into NetworkOwnership for more info.

what I was meaning to say was that either way, server scripts should work, but it didnt and I don’t know why :frowning:

For new people that see this: I would really like to know why the ApplyImpulse() doesn’t work.