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