How to make a part spawn in front of a player

Including rotations, I want it to spawn 5 studs infront of a player but it does but does not get the right rotation… Please help.

Code:

wait(5)
local Brick = script.Parent
local Torso = game.Workspace:FindFirstChild(“OutlookG”).UpperTorso
Brick.Position = Torso.Position + Torso.CFrame.lookVector

excuse me, I am bad at CFrame/Vector math.

24 Likes

to combine cframes, you want to use *

local offset = Vector3.new() -- in your case, Vector3.new(0,0,5), or something like that
Part.CFrame = root.CFrame*CFrame.new(offset) -- should offset while keeping rotations of root.CFrame

In this example, Part is the part you want to put in front of the player, root is the humanoidrootpart, and offset is the offset from the torso.

I see that you’re using Position, which you shouldn’t do, you want to use the part’s cframe property.

73 Likes

but if i where to use position how would i do that?

You don’t want to use position.
A CFrame value is a composition of position and rotation. If you used position it would be offset because position has a safety feature on it, keeping it from being in the position you set it sometimes.

im using align position so i kinda need position.

CFrame changes the position

1 Like

huh?

alignposition needs positions not cframes.

part.CFrame = CFrame.new(0,0,0) makes the position 0,0,0
setting the cframe will work with align position

1 Like

so like alignposition.Position = CFrame.new(0,0,0)?? because that makes no sense…

alignposition does not have a position property, it uses the position of two attachments and aligns them

I think you’re misunderstanding what CFrame values are, you should read up on them first

~~Documentation - Roblox Creator Hub

New link: https://developer.roblox.com/en-us/api-reference/datatype/CFrame

If you were to use a Vector rather than a CFrame, it won’t always spawn in front of the player as its based on the world space and contains no rotation.

1 Like

oh yea… ok… i forgot lol

1 Like