Push player in a direction hit by the attacker

Hello! I am trying to make a push script. When the attacker pushes another player, I want the player to move back in the direction the attacker hits them. Does anyone know how I can do that?

Thanks!

1 Like

You’d need to apply a force on the victim in the direction of the victim’s negative lookvector (or the perpetrator’s positive lookvector).

Do you have a script?

Yes, I have a script, but it only pushes the victim back.

script.Parent.Push.OnServerEvent:Connect(function(player, toPush)

	local playerRoot = player.Character:FindFirstChild("HumanoidRootPart")
	local pushRoot = toPush:FindFirstChild("HumanoidRootPart")


	if(playerRoot and not playerRoot:FindFirstChild("PushF") and pushRoot and not pushRoot:FindFirstChild("PushF") and (playerRoot.Position - pushRoot.Position).magnitude <= 10) then
		local pushF = Instance.new("BodyVelocity")
		pushF.Name = "PushF"
		pushF.MaxForce = Vector3.new(1000000, 1000000, 1000000)
		pushF.Velocity = (-pushRoot.CFrame.lookVector) * 110

		pushF.Parent = pushRoot

		wait(0.3) 

		pushF:Destroy()
	end
end)
1 Like

Isn’t that what you’re trying to achieve?

No, this only pushes the player back no matter what direction it is pushed from. If you push the victim from the side, the victim will move back in the direction the victim is facing.

Never mind, I see what you mean, you’d use the attacker’s positive lookvector instead of the victim’s negative lookvector.

playerRoot.CFrame.lookVector * 110

3 Likes

Thank you so much for the quick help!