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)
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
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
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