KnockBack for a tool ( Need Help )

Im making a Knockback tool for my game but it push/knockback where the enemy is looking.
I want it so it knockback the enemy where the player that has the tool is looking.
The script I can runs fine.

robloxapp-20220714-1932261.wmv (2.2 MB)

local debounce = false
local hotdog = false
local player = script.Parent.Parent.Parent
local t = script.Parent
local Anim = t.Animation

script.Parent.Activated:Connect(function(P)
	if debounce then return end
	debounce = true
	local char = t.Parent
	local humanoid = char:WaitForChild("Humanoid")
	local plays = humanoid:LoadAnimation(Anim)
	plays:play()
	print('ez')
	script.Parent.Part.Touched:Connect(function(hit)
		if hit and hit.Parent:IsA("Model") and hit.Parent:FindFirstChild("HumanoidRootPart") then
			if hotdog then return end
			hotdog = true
			local KnockBack = Instance.new("BodyVelocity")
			KnockBack.Name = "Knockback"
			KnockBack.MaxForce = Vector3.new(10000,10000,10000)
			KnockBack.Velocity = (hit.Parent.HumanoidRootPart.CFrame.LookVector* -40 + Vector3.new(0,10,0))
			KnockBack.Parent = hit.Parent.HumanoidRootPart
			wait(0.25)
			KnockBack.Velocity = Vector3.new(0,0,0)
			KnockBack:Destroy()
			player.leaderstats.Wacks.Value = player.leaderstats.Wacks.Value + 1
			print("W")
		else
			return
		end
	end)
	wait(0.5)
	debounce = false
	hotdog = false
end)
1 Like

if youre saying you want the enemy to get pushed in the direction of the player then replace

KnockBack.Velocity = (hit.Parent.HumanoidRootPart.CFrame.LookVector* -40 + Vector3.new(0,10,0))

with

KnockBack.Velocity = (t.Parent.HumanoidRootPart.CFrame.LookVector* -40 + Vector3.new(0,10,0))

I assume you are talking about the rotation of the enemy’s HumanoidRootPart. In that case, you want to set the rotation of the enemy’s rootpart equal to the character’s, but plus 180 degrees on the y axis.

local debounce = false
local hotdog = false
local player = script.Parent.Parent.Parent
local t = script.Parent
local Anim = t.Animation

script.Parent.Activated:Connect(function(P)
	if debounce then return end
	debounce = true
	local char = t.Parent
	local humanoid = char:WaitForChild("Humanoid")
	local plays = humanoid:LoadAnimation(Anim)
	plays:play()
	print('ez')
	script.Parent.Part.Touched:Connect(function(hit)
		if hit and hit.Parent:IsA("Model") and hit.Parent:FindFirstChild("HumanoidRootPart") then
			if hotdog then return end
			hotdog = true
			local KnockBack = Instance.new("BodyVelocity")
			KnockBack.Name = "Knockback"
			KnockBack.MaxForce = Vector3.new(10000,10000,10000)
			KnockBack.Velocity = (hit.Parent.HumanoidRootPart.CFrame.LookVector* -40 + Vector3.new(0,10,0))
hit.Parent.HumanoidRootPart.Rotation = player.Character.HumanoidRootPart.Rotation + Vector3.new(0,-180,0)
			KnockBack.Parent = hit.Parent.HumanoidRootPart
			wait(0.25)
			KnockBack.Velocity = Vector3.new(0,0,0)
			KnockBack:Destroy()
			player.leaderstats.Wacks.Value = player.leaderstats.Wacks.Value + 1
			print("W")
		else
			return
		end
	end)
	wait(0.5)
	debounce = false
	hotdog = false
end)
1 Like

I tried that before and It did not work

if it pushes the enemy to you then again replace it with

KnockBack.Velocity = (t.Parent.HumanoidRootPart.CFrame.LookVector* 40 + Vector3.new(0,10,0))

For some reason it didnt even play the animaion

what came up in the output window?

The enemy animation or character animation? Also, is the ‘player’ variable the character or player?

So for some reason its not playing the animaion for the hit

Fix it

If you are talking about the hit animation for the enemy. I don’t see the animation in the script, I only see the attack animation.

The script works like my old script but if I hit the player from the back the person makes the player go to me then the player turn.

And I want it so it push the player anywhere I hit it

Okay, set the rotation before you make the body velocity and set look vector to positive.

thx you it works all I needed to do is set the rotaion before

1 Like