Primary part changes when model is cloned

I’ve been trying to make it where when a model is cloned into workspace it then moves for a little while and gets destroyed. The only problem is whenever the model is cloned into workspace it loses its original PrimaryPart.

Script I have so far -

local CarFolder = game.ReplicatedStorage.Cars
local Dest = CFrame.new(73.783, 49.815, 186.905)

local function Move()
	local items = CarFolder:GetChildren()
	local randomItem = items[math.random(1, #items)]
	local item = randomItem:Clone()
	item.Parent = game.Workspace
	item:SetPrimaryPartCFrame(Dest)
	wait(3)
	for i = 0,1,.001 do
		item:SetPrimaryPartCFrame(item:GetPrimaryPartCFrame() * CFrame.new(0,0,1))
	end
	item:Destroy()
end

while true do
	Move()
end

It gives me an error “Model:GetPrimaryPartCFrame() failed because no PrimaryPart has been set, or the PrimaryPart no longer exists. Please set Model.PrimaryPart before using this.” I would appreciate help, thanks.

You posted this topic a lot, but try to re set the primary part and see if that works.

item.PrimaryPart = PrimaryPartForItem

I post a topic similar too this that helped with something else. Anyways, doing that just gives me the same error that I had before. Because when the model is cloned, all of the parts in the models names change.

image

When you select the Car model, there is a Property named Primary Part.
Select this and click on the item you want as the Model’s PrimaryPart. This can be done in the Explorer window by clicking the item, or in the Workspace window by hovering over the Part and clicking.

The PrimaryPart will be highlighted with a white bounding box.

2 Likes

Yes I already did this. The problem is that when I’m cloning that car model and when it is being cloned the PrimaryPart changes to nothing.

Can you show your script? I want to see where you placed the code that re sets the PrimaryPart.

The code I provided is a script in ServerScriptService.

local CarFolder = game.ReplicatedStorage.Cars
local Dest = CFrame.new(73.783, 49.815, 186.905)

local function Move()
	local items = CarFolder:GetChildren()
	local randomItem = items[math.random(1, #items)]
	local item = randomItem:Clone()
	item.Parent = game.Workspace
	item:SetPrimaryPartCFrame(Dest)
	wait(3)
	for i = 0,1,.001 do
		item:SetPrimaryPartCFrame(item:GetPrimaryPartCFrame() * CFrame.new(0,0,1))
	end
	item:Destroy()
end

while true do
	Move()
end

I don’t see you setting the primary part in the script?

I suggest re setting the primary part after you clone the part.