Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make a part that matches both the position and the rotation of another object?

So, I have a part I want to clone and I want to position it inside another part and have that same part's rotation. Here's an example:

local clone = game.Workspace.Part:Clone()
clone.Parent = game.Workspace
clone.Position = Vector3.new(game.Workspace.Part2.Position)
clone.Rotation = Vector3.new(game.Workspace.Part2.Rotation)

Doing the above won't work, because it doesn't change the rotation and the position of the cloned part is above the part I want it to be in, not inside. Can anyone help me out?

1 comment

0

Are you sure it is Vector3 or is it CFrame?

1 answer

You just need to use CFrame, as it preserves rotation and allows objects to move through other objects.

Format:

part1.CFrame = part2.CFrame

Edit: exact code I used

local clone = game.Workspace.Part:Clone()
clone.Parent = game.Workspace
clone.CFrame = game.Workspace.Part2.CFrame

3 comments

0

That does the positional part of what I need, but the rotation doesn't change.

0

It works perfectly when I test it. I edited my post with the exact code i used.

0

Try rotating part2 and then testing it. You'll notice the rotation of part stays the same, regardless of part2's rotation.

This discussion is preserved as it was. New answers, comments, and votes are closed.