Why is my character off set with actual character position

So I made small snip of code where the player follows the other person with 5 stud offset behind him, it works at times and sometimes the player is offset 5 studs in Z direction for some reason and I don’t have real clue why


game.ReplicatedStorage.CuffEvents.MainEvent.OnServerEvent:Connect(function(plr,Player)
		
	while targetreached == false do
		wait(0.1)
		
		local ToPoint = Vector3.new(game.Workspace[plr.Name].HumanoidRootPart.Position.X + 8,game.Workspace[plr.Name].HumanoidRootPart.Position.Y,game.Workspace[plr.Name].HumanoidRootPart.Position.Z)
		
		Player.Humanoid:MoveTo(ToPoint)
	end
end)

image

local ToPoint = Vector3.new(game.Workspace[plr.Name].HumanoidRootPart.Position.X + 8,game.Workspace[plr.Name].HumanoidRootPart.Position.Y,game.Workspace[plr.Name].HumanoidRootPart.Position.Z)

You’re adding 8 studs to the player’s X position no matter which way they’re facing. If you want the ToPoint to be behind the player, you need to multiply your distance by the player’s LookVector and subtract that from their position.

local HumanoidRootPart = workspace[plr.Name].HumanoidRootPart
local Offset = 5 * HumanoidRootPart.CFrame.LookVector
local ToPoint = HumanoidRootPart.Position - Offset
1 Like