How do I spawn a part a certain distance away from the player?

I want to spawn a part in the workspace and have it a certain distance away from the player as well as have it spawn at a height, how can I do this?

1 Like

You could spawn it at the Players HumanoidRootPart CFrame then use a +Vector3.new(0,0,0) to give it an offset.
Example:

Part.CFrame = PlayerObject.Character.HumanoidRootPart.CFrame + Vector3.new(0,0,0) -- The Vector3 is the offset from the HumanoidRootPart

My usual go-to is:

part.CFrame = player.Character.HumanoidRootPart.CFrame * CFrame.new(x, y, z)

Thank you both for the suggestions.

Not enough information has been given regarding what “spawning a part a certain distance away from the player” means.

The first answer concerns world space while the second one concerns object space.

To clarify, the first answer wouldn’t take in account the character’s rotation while the second would do.

The question is no longer the same, but generally speaking, if you have a point A and a point B, the direction is given by (B - A) which will result in a vector that starts from A and goes to B.