:Clone doesnt work properly

hi im trying to change CFrame of models primary part, but it doesnt work and gives error:
image

local function SpawnTower(TowerInfo,modelName)
	local clientmodel = Replicatedstorage.FirstLVL:FindFirstChild(modelName)
	local x = clientmodel:Clone()
	local y = x
	print(x.PrimaryPart)
	y.Parent = game.Workspace.Towers:FindFirstChild(TowerInfo.ID)
	y:PivotTo(CFrame.new(TowerInfo.Position + Vector3.new(0,(1.043 + SpawnTower.PrimaryPart.Size.Y / 2),0)))
end
1 Like

Here’s the issue. You are referring to the function’s name(or identifier) in this piece of code. To cut down some redundancy:

local function SpawnTower(TowerInfo, modelName)
	local clientModel = Replicatedstorage.FirstLVL:FindFirstChild(modelName)
	local cloneModel = clientModel:Clone()
	print(cloneModel.PrimaryPart)
	cloneModel.Parent = workspace.Towers:FindFirstChild(TowerInfo.ID)
	cloneModel:PivotTo(CFrame.new(TowerInfo.Position + Vector3.new(0,(1.043 + cloneModel.PrimaryPart.Size.Y / 2),0)))
end
1 Like

The function is named SpawnTower, so that’s why it’s giving that error message.