Parent property locked error message

I have a script that makes the player put a piece of chicken in an oven, when he does put one in, it clones the model from RS(replicated storage) then when he takes it out, it destroys the cloned model. Put when he wants to put a brand new one in, I get an error message

“The Parent property of RawChickenPiece is locked, current parent: NULL, new parent Workspace”

The code:


local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DB = false

local proximityR = script.Parent
local proximityC = script.Parent.Parent.Parent.Cooked.ProximityPrompt
local proximityB = script.Parent.Parent.Parent.Burnt.ProximityPrompt

local ChickenModel = ReplicatedStorage.RawChicken
local ChickenSlice = ReplicatedStorage.RawChickenPiece
local OvenLight = game.Workspace.Oven1.OvenLight.SpotLight
local OvenHeaters = game.Workspace.Oven1.Heaters
local taken = false

--sounds
local Sizzle = script.Parent.Sizzle
local On = script.Parent.On
local Ding = script.Parent.CookedDing
local Door = script.Parent.Door
local Fire = script.Parent.Fire
--

function Cooked(Player)
	proximityC.Enabled = false
	taken = true
	print("Cooked and ready!!")
	OvenHeaters.Color = Color3.fromRGB(27, 42, 53)
	OvenLight.Brightness = 0
	Sizzle.Looped = false
	Sizzle:Stop()
	On.Looped = false
	On:Stop()
	ChickenSlice:Destroy()


	local ChickenCTool = ReplicatedStorage.CookedChicken:Clone()
	local character = Player.Character or Player.CharacterAdded:Wait() -- gets the player's character
	local humanoid = character:FindFirstChildOfClass("Humanoid") -- get the humanoid
	ChickenCTool.Parent = Player.Backpack -- put in backpack
	humanoid:EquipTool(ChickenCTool) --equip the tool
	local weld = Instance.new("Weld")
	weld.Part0 = ChickenCTool.CookedChicken.Handle
	weld.Part1 = character["Right Arm"]
	weld.C0 = CFrame.new(0, 1.07, 0)
	weld.Parent = ChickenCTool.CookedChicken.Handle
	wait(1)
	proximityR.Enabled = true
	DB = false
end

function Burnt(Player)
	print("bruv u burned it")
	ChickenSlice:Destroy()
	proximityB.Enabled = false
	OvenHeaters.Color = Color3.fromRGB(27, 42, 53)
	OvenLight.Brightness = 0
	Sizzle.Looped = false
	Sizzle:Stop()
	On.Looped = false
	On:Stop()

	local ChickenBTool = ReplicatedStorage.BurntChicken:Clone()
	local character = Player.Character or Player.CharacterAdded:Wait() -- gets the player's character
	local humanoid = character:FindFirstChildOfClass("Humanoid") -- get the humanoid
	ChickenBTool.Parent = Player.Backpack -- put in backpack
	humanoid:EquipTool(ChickenBTool) --equip the tool
	local weld = Instance.new("Weld")
	weld.Part0 = ChickenBTool.BurntChicken.Handle
	weld.Part1 = character["Right Arm"]
	weld.C0 = CFrame.new(0, 1.07, 0)
	weld.Parent = ChickenBTool.BurntChicken.Handle
	wait(1)
	proximityR.Enabled = true
	DB = false
end



proximityB.Enabled = false
proximityC.Enabled = false

proximityR.Triggered:Connect(function(Player)
	if not DB then
		local Chicken = Player.Character:FindFirstChild("RawChicken")
		if Chicken then
			DB = true
		
			
			--|Position and cloning|--
			
			Chicken:Destroy()
			ChickenSlice:Clone()
			ChickenSlice.Parent = workspace
			ChickenSlice.PrimaryPart = ChickenSlice.Union
            ChickenSlice:SetPrimaryPartCFrame(CFrame.new(42.643, 2.057, -34.316))
			proximityR.Enabled = false
			--|Looks|--
			OvenHeaters.Color = Color3.fromRGB(255, 107, 18)
			OvenLight.Brightness = 100
			
			--|Cooking|--
			
		
			Door:Play()
			wait(.5)
			Sizzle:Play()
			Sizzle.Looped = true
			On:Play()
			On.Looped = true
			wait(5)
			ChickenSlice.Union.Color = Color3.fromRGB(232, 198, 136)
			 proximityC.Enabled = true
			  print("ready")
		       proximityC.Triggered:Connect(Cooked) 
			    Ding:Play()
			wait(5)
			
			--|Burnt|--
			
			if not taken then
			   proximityC.Enabled = false
				proximityB.Enabled = true
				 ChickenSlice.Union.Color = Color3.fromRGB(39, 39, 39)
				  proximityB.Triggered:Connect(Burnt) 
			       print("Burning")
				    
				
				
				
			   end
			end
		end
	end)

What the heck is wrong??

What line does it say the error is on?

line 92, where it says “ChickenSlice.Parent = workspace” near the beginning of the proximityR function.

Hmm. I think the problem is that, when you use :Clone(), it creates a new instance and is trying to set the parent as the same as the original, however at the exact same time, you are trying to set the parent as the workspace. You can (maybe) solve this by replacing the proximityR function with this new one:

proximityR.Triggered:Connect(function(Player)
	if not DB then
		local Chicken = Player.Character:FindFirstChild("RawChicken")
		if Chicken then
			DB = true
		
			
			--|Position and cloning|--
			
			Chicken:Destroy()
			local newChickenSlice = ChickenSlice:Clone()
			newChickenSlice.PrimaryPart = ChickenSlice.Union
            newChickenSlice:SetPrimaryPartCFrame(CFrame.new(42.643, 2.057, -34.316))
			proximityR.Enabled = false
			--|Looks|--
			OvenHeaters.Color = Color3.fromRGB(255, 107, 18)
			OvenLight.Brightness = 100
            task.wait()
			newChickenSlice.Parent = workspace			
			--|Cooking|--
			
		
			Door:Play()
			wait(.5)
			Sizzle:Play()
			Sizzle.Looped = true
			On:Play()
			On.Looped = true
			wait(5)
			newChickenSlice.Union.Color = Color3.fromRGB(232, 198, 136)
			 proximityC.Enabled = true
			  print("ready")
		       proximityC.Triggered:Connect(Cooked) 
			    Ding:Play()
			wait(5)
			
			--|Burnt|--
			
			if not taken then
			   proximityC.Enabled = false
				proximityB.Enabled = true
				 newChickenSlice.Union.Color = Color3.fromRGB(39, 39, 39)
				  proximityB.Triggered:Connect(Burnt) 
			       print("Burning")
			   end
			end
		end
	end)

In this new version, after configuring the newChickenSlice, we wait one “task”, which allows the clone’s parent to be set, then we change it. I also set a newChickenSlice variable so you configure the new one, not the old. I hope this solves your problem!

that got rid of the first error, but now it is just telling me that union is not a valid member of RawChickenPiece on line 93 of this new script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DB = false

local proximityR = script.Parent
local proximityC = script.Parent.Parent.Parent.Cooked.ProximityPrompt
local proximityB = script.Parent.Parent.Parent.Burnt.ProximityPrompt

local ChickenModel = ReplicatedStorage.RawChicken
local ChickenSlice = ReplicatedStorage.RawChickenPiece
local OvenLight = game.Workspace.Oven1.OvenLight.SpotLight
local OvenHeaters = game.Workspace.Oven1.Heaters
local taken = false

--sounds
local Sizzle = script.Parent.Sizzle
local On = script.Parent.On
local Ding = script.Parent.CookedDing
local Door = script.Parent.Door
local Fire = script.Parent.Fire
--
local NewChickenSlice = ChickenSlice:Clone()

function Cooked(Player)
	proximityC.Enabled = false
	taken = true
	print("Cooked and ready!!")
	OvenHeaters.Color = Color3.fromRGB(27, 42, 53)
	OvenLight.Brightness = 0
	Sizzle.Looped = false
	Sizzle:Stop()
	On.Looped = false
	On:Stop()
	NewChickenSlice:Destroy()


	local ChickenCTool = ReplicatedStorage.CookedChicken:Clone()
	local character = Player.Character or Player.CharacterAdded:Wait() -- gets the player's character
	local humanoid = character:FindFirstChildOfClass("Humanoid") -- get the humanoid
	ChickenCTool.Parent = Player.Backpack -- put in backpack
	humanoid:EquipTool(ChickenCTool) --equip the tool
	local weld = Instance.new("Weld")
	weld.Part0 = ChickenCTool.CookedChicken.Handle
	weld.Part1 = character["Right Arm"]
	weld.C0 = CFrame.new(0, 1.07, 0)
	weld.Parent = ChickenCTool.CookedChicken.Handle
	wait(1)
	proximityR.Enabled = true
	DB = false
end

function Burnt(Player)
	print("bruv u burned it")
	NewChickenSlice:Destroy()
	proximityB.Enabled = false
	OvenHeaters.Color = Color3.fromRGB(27, 42, 53)
	OvenLight.Brightness = 0
	Sizzle.Looped = false
	Sizzle:Stop()
	On.Looped = false
	On:Stop()

	local ChickenBTool = ReplicatedStorage.BurntChicken:Clone()
	local character = Player.Character or Player.CharacterAdded:Wait() -- gets the player's character
	local humanoid = character:FindFirstChildOfClass("Humanoid") -- get the humanoid
	ChickenBTool.Parent = Player.Backpack -- put in backpack
	humanoid:EquipTool(ChickenBTool) --equip the tool
	local weld = Instance.new("Weld")
	weld.Part0 = ChickenBTool.BurntChicken.Handle
	weld.Part1 = character["Right Arm"]
	weld.C0 = CFrame.new(0, 1.07, 0)
	weld.Parent = ChickenBTool.BurntChicken.Handle
	wait(1)
	proximityR.Enabled = true
	DB = false
end



proximityB.Enabled = false
proximityC.Enabled = false

proximityR.Triggered:Connect(function(Player)
	if not DB then
		local Chicken = Player.Character:FindFirstChild("RawChicken")
		if Chicken then
			DB = true


			--|Position and cloning|--

			Chicken:Destroy()
			
			NewChickenSlice.PrimaryPart = NewChickenSlice.Union
			NewChickenSlice:SetPrimaryPartCFrame(CFrame.new(42.643, 2.057, -34.316))
			proximityR.Enabled = false
			--|Looks|--
			OvenHeaters.Color = Color3.fromRGB(255, 107, 18)
			OvenLight.Brightness = 100
			task.wait()
			NewChickenSlice.Parent = workspace
			--|Cooking|--


			Door:Play()
			wait(.5)
			Sizzle:Play()
			Sizzle.Looped = true
			On:Play()
			On.Looped = true
			wait(5)
			NewChickenSlice.Union.Color = Color3.fromRGB(232, 198, 136)
			proximityC.Enabled = true
			print("ready")
			proximityC.Triggered:Connect(Cooked) 
			Ding:Play()
			wait(5)

			--|Burnt|--

			if not taken then
				proximityC.Enabled = false
				proximityB.Enabled = true
				NewChickenSlice.Union.Color = Color3.fromRGB(39, 39, 39)
				proximityB.Triggered:Connect(Burnt) 
				print("Burning")




			end
		end
	end
end)

I assume there’s a Union under the original “ChickenSlice”, but not in the “NewChickenSlice”, and for some reason you’re getting that error. I think it could be because when you set the variable “NewChickenSlice” as the “ChickenSlice”'s clone, it’s outside of the .Triggered function and only happens once, which might not be what you want. If it is, then you should check the Explorer window if the Union is in there.

Also, on line 94:

NewChickenSlice:SetPrimaryPartCFrame(CFrame.new(42.643, 2.057, -34.316))

you should use :PivotTo() instead of :SetPrimaryPartCFrame(), since it is deprecated. To my knowledge, however, :PivotTo() is exactly the same so I’m not sure why they deprecated it. Maybe just use :PivotTo() anways.

Checked explorer and replicated storage, and Chicken Slice always has a union, even while playing the game.

Tell me if this topic is too old because I don’t know when people should stop responding but…

Maybe this will help you