Get players facing direction?

Im trying to make it so when a player drives a boat, if they hit land, itll teleport the boat back 10 or so studs so that there not “driving” on land, but its not working at all, any help?

local player = nil

script.Parent:GetPropertyChangedSignal("Occupant"):Connect(function()
	if script.Parent.Occupant then
		player = Players:GetPlayerFromCharacter(script.Parent.Occupant.Parent)
	else
		if not script.Parent.Occupant then
			player = nil
		end
	end
end)

function checkwater()
	for i,v in pairs(script.Parent.Parent.WaterTouch:GetTouchingParts()) do
		print(v)
		if v.Name == "Wooter" then
			onwater = true
			print("on water true")
		else
			if v.Name == "Sand Dune" then
				onwater = false
				local direction = player.Character:FindFirstChild("HumanoidRootPart").CFrame + layer.Character:FindFirstChild("HumanoidRootPart").CFrame.LookVector - 5
				script.Parent.CFrame = direction
			print("on water false")
		end
	end
	end
end
1 Like

Not sure if this is cause of your issue, but you would want to multiply your look vector by a constant (i.e. * -5) before adding it to another vector. Adding or subtracting a constant will not do what you want and I would think triggers an error anyway.

1 Like

layer.Character doesnt exist. Player.Character on the line where you manipulate the cframe. Also, use multiplication when manipulating cframe

Would rework your CFraming here a bit, because they are so many errors

local hmr = player.Character.HumanoidRootPart
local blowback = -hmr.CFrame.LookVector * 10
script.Parent.Parent.CFrame += blowback