Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Attempting to make knock-back on my sword, to knock enemies back! But how do I make it work?

I am making a game were you are using guns (those are working no problem) and swords to fight slime monsters. But the problem is that I would like to make the swords knock the enemies back on impact so that the sword becomes more reliable to use!

Here is the script I attempted to use:

door = script.Parent

function onTouch(hit)
	if hit.Parent == nil then return end
	local h = hit.Parent:FindFirstChild("Zombie")
	if h ~= nil then
		hit.Parent.Torso.Velocity=door.CFrame.lookVector * -100
end
door.Touched:connect(onTouch)

It only works when the enemy is standing still, when they move it no longer works. How can I resolve this issue? (I am also doing this in a filtering enabled game) If you can help me out with this, I would be more than happy! Thanks!

1 answer

You can use a BodyVelocity for knockback. Just parent it to the torso, and set the Velocity of it to the player's (with the sword) torso's lookVector, and add something like Vector3.new(0,2,0) to that so that the enemy leaves the ground and reduces friction which would make them knock back using less power.

To delete the BodyVelocity use game.Debris:AddItem(BV) or just simply wait and delete it.

This discussion is preserved as it was. New answers, comments, and votes are closed.