Unable to cast Vector3 to CoordinateFrame

I’m trying to make a script that duplicates a random model of 3 models and puts it in the position where a certain part is located. I want the orientation and position to be the same as the model.

everything’s working except for the orientation and I’m not understanding why I’m getting this error.

thank you <3

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.Orientation)
	new1.PrimaryPart = new1:WaitForChild("Center")
	new1.Parent = game.Workspace
	new1:SetPrimaryPartCFrame(CFrame.new(new1.PrimaryPart.Position, script.Parent))
elseif fe == 2 then
	local new2 = tem2:Clone()
	local pivot2 = new2:GetPivot()
	new2:PivotTo(script.Parent.Orientation)
	new2.PrimaryPart = new2:WaitForChild("Center")
	new2.Parent = game.Workspace
	new2:SetPrimaryPartCFrame(CFrame.new(new2.PrimaryPart.Position, script.Parent))
elseif fe == 3 then
	local new3 = tem3:Clone()
	local pivot3 = new3:GetPivot()
	new3:PivotTo(script.Parent.Orientation)
	new3.PrimaryPart = new3:WaitForChild("Center")
	new3.Parent = game.Workspace
	new3:SetPrimaryPartCFrame(CFrame.new(new3.PrimaryPart.Position, script.Parent))
end
1 Like

PivotTo takes a CFrame. Maybe you meant something like

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

Also

I think you’re missing a .Position after script.Parent?

ok i changed the stuff but im still getting this error:

the new script is

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(CFrame.new(new1.PrimaryPart.Position, 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(CFrame.new(new2.PrimaryPart.Position, 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(CFrame.new(new3.PrimaryPart.Position, script.Parent.Orientation))

end

error remains: Unable to cast Vector3 to CoordinateFrame

Your pivotTo calls are still being fed Vector3s rather than CFrames

i changed it to 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(CFrame.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(CFrame.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(CFrame.new(new3.PrimaryPart.Position, CFrame.new(script.Parent.Orientation)))
end

but its still erroring same thing

Hi dev !!!

you need to use :MoveTo method, because roblox don’t support SetPrimaryPartCFrame so you just change the SetPrimaryPartCFrame to MoveTo.

hope this is work !!!

2 Likes