Rotating and Positioning Parts by using ToWorldSpace() at the same time

I want to make a script where a part will be moved to front of players and rotated to look at our player’s front. But when I use this script:

Part.CFrame = RootPart.CFrame:ToWorldSpace(,0,-5));
Part.CFrame = RootPart.CFrame:ToWorldSpace(CFrame.Angles(0,0,0));

Instead of moving part 5 studs in front of player and rotating it to look at our player’s front, it rotates the part to “random” rotation and put the part in (0,0,0) relative to player.

Expectation (Abandon those 2 parts in front of first part)

Reality (Abandon that part behind player)

I’ve browsed and I can’t find anyone with same problem as me, so I think this is not duplicate (?).

How do I fix my problem?

Your second line disregards the first by placing the part again relative to the root part.

Do both operations at once (the position and the rotation) to avoid that, or use the new CFrame you’ve created as the input for the second line instead of the root part CFrame.

If you just want the block 5 studs in front of the player’s root part, you could simply do:

Part.CFrame = RootPart.CFrame:ToWorldSpace(, 0, -5))

which is the same as

Part.CFrame = RootPart.CFrame *, 0, -5)

Which will orientate Part exactly the same as RootPart, and will place it five studs in front.

1 Like

Oh, I see, It fixed the problem, thank you.