Can't move a model after being cloned, deleted then cloned again

Okay so I made a video showing my issue because I have no idea how to properly typing it out without making a big fool of me self.

Video: Scripting Help Plz - YouTube

Error Message:
Model:SetPrimaryPartCFrame() failed because no PrimaryPart has been set, or the PrimaryPart no longer exists. Please set Model.PrimaryPart before using this.

The only script that is involved with the removal/deletion of the fully grown carrot is this script right here:

script.Parent.Triggered:Connect(function(player)
	script.Parent.Enabled = false
	
	-- Collection Code Here
	
	script.Parent.Parent.Parent.Parent.Parent.ProximityPrompt.Core.TileInUse.Value = false
	print("Carrot Removed")
	wait(.05)
	script.Parent.Parent.Parent.Parent.Parent.SeedPlacement.CarrotSeedModel:Remove()
	wait(.05)
	script.Parent.Parent.Parent.Parent.CarrotFull:Remove()
	wait(.05)
	print("You Shouldn't See This?")
	
end)

The script above is located within this set up.
Carrat2

the script below is the “CarrotActivationScript” I don’t think this script is needed but I’ll add it anyways just in case.

local CarrotGrow = game.ReplicatedStorage.Farming.Produce.FarmSpringCrop.Carrots.CarrotGrowth
local CarrotFull = game.ReplicatedStorage.Farming.Produce.FarmSpringCrop.Carrots.CarrotFull

local CarrotClone = CarrotGrow:Clone()
local CarrotFullClone = CarrotFull:Clone()
--local CarrotClone2 = CarrotClone:Clone()

local ReloadTime = game.Workspace.Triggers.Seeds.CarrotReloadTime

script.Parent.Triggered:Connect(function(player)
	
	script.Parent.Enabled = false
	print("Beginning Carrot Phases")
	wait(ReloadTime.Value)
	wait(.5)
	script.Parent.Parent.Transparency = 1
	
	CarrotClone:Clone()
	CarrotClone.Parent = script.Parent.Parent.Parent.Parent.Parent.Carrot10Placement
	CarrotClone:SetPrimaryPartCFrame(CFrame.new(script.Parent.Parent.Parent.Parent.Parent.Carrot10Placement.WorldPosition))
	print("Stage 1 Complete")
	wait(ReloadTime.Value)
	
	CarrotClone.Parent = script.Parent.Parent.Parent.Parent.Parent.Carrot25Placement
	CarrotClone:SetPrimaryPartCFrame(CFrame.new(script.Parent.Parent.Parent.Parent.Parent.Carrot25Placement.WorldPosition))
	print("Stage 2 Complete")
	wait(ReloadTime.Value)
	
	script.Parent.Parent.Parent.Parent.Parent.Carrot25Placement.CarrotGrowth:Destroy()
	CarrotFullClone:Clone()
	CarrotFullClone.Parent = script.Parent.Parent.Parent.Parent.Parent.CarrotFullPlacement
	CarrotFullClone:SetPrimaryPartCFrame(CFrame.new(script.Parent.Parent.Parent.Parent.Parent.CarrotFullPlacement.WorldPosition))
	print("Stage 3 Complete")
	wait(.5)
	print("Carrot Complete")
	
end)

Below is the full hierarchy of the system (Please note that the image above, for the sake of understanding; “CarrotFull” was placed into CarrotFullPlacement for the sake of this photo, It’s originally held within the Replicated stroage till its cloned into the “CarrotFullPlacement” Attachment)

Full Hierarchy:
Carrot Hierarchy

If any more info is need do let me know, because Im honestly stumped. Like I understand what the error means; There is no primary part, but if it worked the first time, why wouldn’t it work the second time?

I’m sorry if this post is a jumbled mess but I’ve been working on this for the past few hours and I’m honestly stumped.

2 Likes

On a side note, Remove has been deprecated for years. You should be using Destroy.

In any case, if the problem of your thread is related to the error message, then that needs to be read very literally in that the model you’re attempting to call SetPrimaryPartCFrame on does not have a PrimaryPart set. Go ahead and set one.

1 Like

When you click model, look into the properties of the “model”, there will be an empty box for PrimaryPart, click the box and click 1 of the parts you want to set as PrimaryPart for your carrot.

1 Like

It does :slight_smile: Just for some reason when it’s cloned again it takes just he shell of the clone.
and I’ve tried to code it to set the primary part as the CarrotSeedsUnion but it tells me

"CarrotSeedsUnion is not a valid member of Model ("Workspace.Tile.SeedPlacement.CarrotSeedModel")

and if I don’t tell it to set its primary part it just gives me the issue mentioned above in this post. :frowning:
Img1 is before, img 2 is after.


I do want to thank you tho, as annoying as I may sound haha!

ps. If i change :Remove() to :Destroy() it tells me,

The Parent property of CarrotSeedModel is locked, current parent: NULL, new parent SeedPlacement

Sorry I got side tracked with stuff. Yeah It has a primary part from the start. For some reason when i clone it again on the same Tile, it doesn’t take its children. Just the model.

I’m not sure if this would work but for your carrotactivationscript try this instead.

local CarrotGrow = game.ReplicatedStorage.Farming.Produce.FarmSpringCrop.Carrots.CarrotGrowth
local CarrotFull = game.ReplicatedStorage.Farming.Produce.FarmSpringCrop.Carrots.CarrotFull

local ReloadTime = game.Workspace.Triggers.Seeds.CarrotReloadTime

script.Parent.Triggered:Connect(function(player)
	local CarrotClone = CarrotGrow:Clone()
    local CarrotFullClone = CarrotFull:Clone()
	
	script.Parent.Enabled = false
	print("Beginning Carrot Phases")
	wait(ReloadTime.Value)
	wait(.5)
	script.Parent.Parent.Transparency = 1

	CarrotClone.Parent = script.Parent.Parent.Parent.Parent.Parent.Carrot10Placement
	CarrotClone:SetPrimaryPartCFrame(CFrame.new(script.Parent.Parent.Parent.Parent.Parent.Carrot10Placement.WorldPosition))
	print("Stage 1 Complete")
	wait(ReloadTime.Value)
	
	CarrotClone.Parent = script.Parent.Parent.Parent.Parent.Parent.Carrot25Placement
	CarrotClone:SetPrimaryPartCFrame(CFrame.new(script.Parent.Parent.Parent.Parent.Parent.Carrot25Placement.WorldPosition))
	print("Stage 2 Complete")
	wait(ReloadTime.Value)
	
	script.Parent.Parent.Parent.Parent.Parent.Carrot25Placement.CarrotGrowth:Destroy()
	
	CarrotFullClone.Parent = script.Parent.Parent.Parent.Parent.Parent.CarrotFullPlacement
	CarrotFullClone:SetPrimaryPartCFrame(CFrame.new(script.Parent.Parent.Parent.Parent.Parent.CarrotFullPlacement.WorldPosition))
	print("Stage 3 Complete")
	wait(.5)
	print("Carrot Complete")
	
end)
1 Like

Hey, Thank you, Sadly it did not work, but If I may be a pain 1 final time; If no, just let me know. But the error is directing me here. For some reason. Within the Core Script of my Tile. IMG below.

Error code is the same from the start
(Model:SetPrimaryPartCFrame() failed because no PrimaryPart has been set, or the PrimaryPart no longer exists. Please set Model.PrimaryPart before using this.)

I tried to tell it what the Primary Part is, but because it only happens the second time around idk whats wrong. xD

(If you need the code in typed form, from above, lmk).

Is your strawberry seed affected by the same problem?

No, because the strawberry regrows, It doesn’t get removed :confused: I know at some point I’ll have a tool to remove the strawberry plant but I’ll do that once the carrot gets solved. Only because If I want to remove a model via a tool, I feel like that’s more complex than just simply removing a model via Proximity Prompt. I’m just so confused as to why it doesn’t work the second time xD

Oh and can I get the text form for this? I’ll try to figure something out for you.

this is the script for “Core” script. Its from Line 0 - 52. The rest is basically just the same block set up but for the rest of the produce :slight_smile: And Thank you so much. I hate to keep pestering like this so just know that even if there is no solution; I’m thankful for your assistance!

-- Variables Below --
local StrawberrySeedOriginal = game.ReplicatedStorage.Farming.Produce.BareSeeds.StrawberrySeedModel
local StrawberrySeedClone = StrawberrySeedOriginal:Clone()
local CarrotSeedOriginal = game.ReplicatedStorage.Farming.Produce.BareSeeds.CarrotSeedModel
local CarrotSeedClone = CarrotSeedOriginal:Clone()
local PotatoSeedOriginal = game.ReplicatedStorage.Farming.Produce.BareSeeds.PotatoSeedModel
local PotatoSeedClone = PotatoSeedOriginal:Clone()
local CabbageSeedOriginal = game.ReplicatedStorage.Farming.Produce.BareSeeds.CabbageSeedModel
local CabbageSeedClone = CabbageSeedOriginal:Clone()
local SpinachSeedOriginal = game.ReplicatedStorage.Farming.Produce.BareSeeds.SpinachSeedModel
local SpinachSeedClone = SpinachSeedOriginal:Clone()
local SpringOnionSeedOriginal = game.ReplicatedStorage.Farming.Produce.BareSeeds.SpringOnionSeedModel
local SpringOnionClone = SpringOnionSeedOriginal:Clone()
local LettuceSeedOriginal = game.ReplicatedStorage.Farming.Produce.BareSeeds.LettuceSeedModel
local LettuceSeedClone = LettuceSeedOriginal:Clone()

local ObjectTextName = script.Parent
local TileInUse = script.TileInUse
local ProximityPrompt = game.Workspace.Triggers.EnableProximityPrompt

local SeedNumber = game.Workspace.Triggers.SeedNumber


script.Parent.Triggered:Connect(function(player)
	print("Tile In Use")
	TileInUse.Value = true

	if SeedNumber.Value == 0 then
		print("No Seed Established")
	end

	if SeedNumber.Value == 1 then
		print("Strawberry Seed")
		if TileInUse.Value == false then
			script.Parent.Enabled = true
		end
		StrawberrySeedClone:Clone()
		StrawberrySeedClone.Parent = script.Parent.Parent.SeedPlacement
		StrawberrySeedClone:FindFirstChild("StrawberrySeedsUnion")
		StrawberrySeedClone:SetPrimaryPartCFrame(CFrame.new(script.Parent.Parent.SeedPlacement.WorldPosition))
	end

	if SeedNumber.Value == 2 then
		print("Carrot Seed")
		CarrotSeedClone:Clone()
		CarrotSeedClone.Parent = script.Parent.Parent.SeedPlacement
		wait(.05)
		CarrotSeedClone:FindFirstChild("CarrotSeedsUnion")
		CarrotSeedClone.PrimaryPart = script.Parent.Parent.SeedPlacement.CarrotSeedModel:FindFirstChild("CarrotSeedsUnion")
		CarrotSeedClone:SetPrimaryPartCFrame(CFrame.new(script.Parent.Parent.SeedPlacement.WorldPosition))

	end

Alright give me 5-10 minutes cause I’m trying to write the script for you on mobile LEL

Take your time, I’m in no rush :smiley: I’m not forcing you!

-- Variables Below --
local StrawberrySeedOriginal = game.ReplicatedStorage.Farming.Produce.BareSeeds.StrawberrySeedModel

local CarrotSeedOriginal = game.ReplicatedStorage.Farming.Produce.BareSeeds.CarrotSeedModel

local PotatoSeedOriginal = game.ReplicatedStorage.Farming.Produce.BareSeeds.PotatoSeedModel
local PotatoSeedClone = PotatoSeedOriginal:Clone()
local CabbageSeedOriginal = game.ReplicatedStorage.Farming.Produce.BareSeeds.CabbageSeedModel
local CabbageSeedClone = CabbageSeedOriginal:Clone()
local SpinachSeedOriginal = game.ReplicatedStorage.Farming.Produce.BareSeeds.SpinachSeedModel
local SpinachSeedClone = SpinachSeedOriginal:Clone()
local SpringOnionSeedOriginal = game.ReplicatedStorage.Farming.Produce.BareSeeds.SpringOnionSeedModel
local SpringOnionClone = SpringOnionSeedOriginal:Clone()
local LettuceSeedOriginal = game.ReplicatedStorage.Farming.Produce.BareSeeds.LettuceSeedModel
local LettuceSeedClone = LettuceSeedOriginal:Clone()

local ObjectTextName = script.Parent
local TileInUse = script.TileInUse
local ProximityPrompt = game.Workspace.Triggers.EnableProximityPrompt

local SeedNumber = game.Workspace.Triggers.SeedNumber


script.Parent.Triggered:Connect(function(player)
	print("Tile In Use")
	TileInUse.Value = true

	if SeedNumber.Value == 0 then
		print("No Seed Established")
	end

	if SeedNumber.Value == 1 then
		print("Strawberry Seed")
		if TileInUse.Value == false then
			script.Parent.Enabled = true
		end
		local Clone = StrawberrySeedOriginal:Clone()
		Clone.Parent = script.Parent.Parent.SeedPlacement
		Clone:SetPrimaryPartCFrame(CFrame.new(script.Parent.Parent.SeedPlacement.WorldPosition))
	end

	if SeedNumber.Value == 2 then
		print("Carrot Seed")
		local Clone = CarrotSeedOriginal:Clone()
		Clone.Parent = script.Parent.Parent.SeedPlacement
		wait(.05)
		Clone:SetPrimaryPartCFrame(CFrame.new(script.Parent.Parent.SeedPlacement.WorldPosition))

	end
end)

Alright here you go, try replacing this with your current script.

1 Like

Yes?! You got it! It’s a little buggy on my end but I can fix it. (Basically the tile will check if you are holding seeds and become enabled (via the proximity prompt), and then when something is planted It disables the ProxPrompt for the tile. Simple fix I can figure out lol). Thank you so much!!!

Hope you don’t mind me asking, but what was the problem exactly? I can see it was a cloning issue.

Yes, the problem is with the cloning. You are refering to the first clone so the clone in your function doesn’t do anything.

And the reason why you only get the model when you had the issue is because you did remove() instead of destroy() which basically sets the parent to nil but you can still retrieve it by setting the parent to something else, it also remove the children.

1 Like

Sorry for my late reply, I was fixing my bug issue. But yes I partially understand where you are coming from and I have a general sense that when this happens again I’ll be able to figure it out. Thank you so so much! honestly helped more than you think! :smiley: