Pushing the player back when they get hit

So I am currently trying to push the player back when they get his but its only pushing the player back on the z axis. How could I make it push you the direction that the other player is looking? (I am not that good with CFrame or lookVectors)

local debounce = false

script.Parent.Touched:Connect(function(hit)
    local Hit_Character = hit.Parent:FindFirstChild("Humanoid").Parent or hit.Parent.Parent:FindFirstChild("Humanoid").Parent
    if debounce == false then
    debounce = true
	    local bv = Instance.new("BodyVelocity")
		local offset = Vector3.new()
	    bv.Parent = (Hit_Character.Torso)
	    bv.MaxForce = Vector3.new(10000000,10000000,10000000) -- This can be identified as the power
		bv.Velocity = Vector3.new(0, 50, 100)
	    wait(0.01)
        bv:Destroy()
    end
    wait(1)
    debounce = false
end)
9 Likes
local debounce = false

script.Parent.Touched:Connect(function(hit)
	local Hit_Character = hit.Parent:FindFirstChild("Humanoid").Parent or hit.Parent.Parent:FindFirstChild("Humanoid").Parent
	if debounce == false then
		debounce = true
		local bv = Instance.new("BodyVelocity")
		local offset = Vector3.new()
		bv.Parent = (Hit_Character.Torso)
		bv.MaxForce = Vector3.new(10000000,10000000,10000000) -- This can be identified as the power
		bv.Velocity = Hit_Character.Head.CFrame.LookVector * -50
		wait(0.01)
		bv:Destroy()
	end
	wait(1)
	debounce = false
end)

Try this. -50 is the velocity that will be applied.

3 Likes

It works, but the only thing is that I need it to make me go up and get pushed at the same time, like this .

1 Like

Try this. Now I am adding an UpVector that is multiplied by 50.

local debounce = false

script.Parent.Touched:Connect(function(hit)
	local Hit_Character = hit.Parent:FindFirstChild("Humanoid").Parent or hit.Parent.Parent:FindFirstChild("Humanoid").Parent
	if debounce == false then
		debounce = true
		local bv = Instance.new("BodyVelocity")
		local offset = Vector3.new()
		bv.Parent = (Hit_Character.Torso)
		bv.MaxForce = Vector3.new(10000000,10000000,10000000) -- This can be identified as the power
		bv.Velocity = (Hit_Character.Head.CFrame.LookVector * -50) + (Hit_Character.Head.CFrame.UpVector * 50)
		wait(0.01)
		bv:Destroy()
	end
	wait(1)
	debounce = false
end)
7 Likes

It works, there is probably another method to this which I will try finding but thank you for helping.

2 Likes

Did you find another method to this? I also want to see if there is another way