How to move parts in roblox studio?

im trying to make a script that picks 1 out of 3 types of generators and makes its position and orientation the same as another brick. its working for the most part. the thing thats not working is its position is 0,0,0 instead of the parts.

Script:

local generators = game.Workspace.Template

local tem1 = generators.Template1

local tem2 = generators.Template2

local tem3 = generators.Template3

local fe = math.random(1,3)

if fe == 1 then

local new1 = tem1:Clone()

local pivot1 = new1:GetPivot()

new1:PivotTo(script.Parent.CFrame.Rotation)

new1.PrimaryPart = new1:WaitForChild("Center")

new1.Parent = game.Workspace

new1:SetPrimaryPartCFrame(Vector3.new(new1.PrimaryPart.Position, CFrame.new(script.Parent.Orientation)))

elseif fe == 2 then

local new2 = tem2:Clone()

local pivot2 = new2:GetPivot()

new2:PivotTo(script.Parent.CFrame.Rotation)

new2.PrimaryPart = new2:WaitForChild("Center")

new2.Parent = game.Workspace

new2:SetPrimaryPartCFrame(Vector3.new(new2.PrimaryPart.Position, CFrame.new(script.Parent.Orientation)))

elseif fe == 3 then

local new3 = tem3:Clone()

local pivot3 = new3:GetPivot()

new3:PivotTo(script.Parent.CFrame.Rotation)

new3.PrimaryPart = new3:WaitForChild("Center")

new3.Parent = game.Workspace

new3:SetPrimaryPartCFrame(Vector3.new(new3.PrimaryPart.Position, CFrame.new(script.Parent.Orientation)))

end

error: 20:56:33.727 Workspace.Part i want it to teleport to.Script:28: invalid argument #2 to ‘new’ (Vector3 expected, got CFrame) - Server - Script:28
(WHEN I CHANGE IT TO CFRAME IT SAYS SAME ERROR ABOUT VECTOR3)

model of things in case the script is confusing you and you need workspace view: https://www.roblox.com/library/configure?id=8399360698#!/general

There’s a much, and I mean muuuuch easier way to do this.

To make one part’s position and rotation the same as another’s, all you have to do is use CFrame.

part1.CFrame = part2.CFrame
1 Like

lets try it. i=thank you so much if it works lol

1 Like

CFrame is not a valid member of Model “Workspace.Template3”

(btw its a model not a single part being teleported to a part)

script: local generators = game.Workspace.Template
local tem1 = generators.Template1
local tem2 = generators.Template2
local tem3 = generators.Template3
local fe = math.random(1,3)
if fe == 1 then
	local new1 = tem1:Clone()
	new1.PrimaryPart = new1:WaitForChild("Center")   
	new1.Parent = game.Workspace
	new1.CFrame = script.Parent.CFrame
elseif fe == 2 then
	local new2 = tem2:Clone()
	new2.PrimaryPart = new2:WaitForChild("Center")
	new2.Parent = game.Workspace
	new2.CFrame = script.Parent.CFrame
elseif fe == 3 then
	local new3 = tem3:Clone()
	new3.PrimaryPart = new3:WaitForChild("Center")
	new3.Parent = game.Workspace
	new3.CFrame = script.Parent.CFrame
end

To set it for a model, I would do something like:

model1:SetPrimaryPartCFrame(model2.PrimaryPart.CFrame)

Make sure each model has a PrimaryPart for this to work

21:10:55.541 PrimaryPart is not a valid member of Part “Workspace.Model.Part i want it to teleport to”

my bad i was referring the wrong thing. it worked thanks

1 Like

Ok, so

If you want to set the CFrame of a model to a part, you’ll do:

model1:SetPrimaryPartCFrame(part.CFrame)

If you want to set the CFrame of a model to another model:

model1:SetPrimaryPartCFrame(model2.PrimaryPart.CFrame)

If you want to set the CFrame of a part to a model:

part.CFrame = model.PrimaryPart.CFrame

And if it’s setting the CFrame of a part to another part:

part1.CFrame = part2.CFrame

If you see any errors saying the PrimaryPart is not a part of a model, that is because you haven’t set the model’s PrimaryPart. Doing so is super easy, you just go in the model’s properties and click on the blank spot next to “PrimaryPart” then click on whatever part in the model you want its PrimaryPart to be

3 Likes

i set it but i was referring to the script.parent which was a part inside the model instead of script.parent.parent which is the model itself. thank you so much dude <3

1 Like