local teleporttohrp = game.Workspace:FindFirstChild(shouldberealname):FindFirstChild("HumanoidRootPart")
local shouldteleporthrp = game.Workspace:FindFirstChild(plr.Name):FindFirstChild("HumanoidRootPart")
shouldteleporthrp.CFrame = CFrame.new(teleporttohrp.Position + Vector3.new(5, 0, 0), teleporttohrp.Position)
print("Teleported!")
I did my research but I still have no idea how I could teleport the player 5 stud in front of the target player(depending on where the target is facing) instead of having a fixed Vector3.new(5, 0, 0) value.
The code is making my eyes bleed… But anyways, setting the CFrame of the root part is really just a bad way of teleporting a player. Try using character:PivotTo(cframe)
If you wanna teleport the player 5 studs from where they are, you can try this:
This code should do the trick, as @KeegansPerun says, we need to get the LookVector of the player’s CFrame, to represent the front of us.
local teleportTo: Model = game.Workspace:WaitForChild(shouldberealname, 2)
if not teleportTo then
return
end
local teleportToPivot: CFrame = teleportTo:GetPivot()
local shouldTeleport: Model = game.Workspace:WaitForChild(plr.Name, 2)
if not shouldTeleport then
return
end
shouldTeleport:PivotTo(teleportToPivot + (teleportToPivot.LookVector * 5))
print("Teleported!")
This won’t always spawn the player in front of them though, the player could be in the rotation of another axis, therefore ‘Z’ won’t be the front of the player, LookVector is a better thing to use in this case.