Cloning Not Working

I’m making a small project where the player is looking at a plate, and when they click the keys E, R, F, C, and X, they spawn in from the sky parts of a burger, like cheese, tomatos, and bread, each corresponding to a certain key. Once there is 6 ingredients added, then the burger and the plate slide(tween) to the left and are destroyed. A few seconds later a new plate slides from the right to in front of the player.

It works perfectly fine the first time. However, the second time around it stops working and glitches. The plate doesn’t slide to the left and a few more rounds of placing the ingredients just breaks it.

I’ve looked around but couldn’t really find any solutions, and I spent countless hours trying to fix it. Such as renaming the newPlate to plate because maybe it couldn’t find it, and moving the entire module script into the same Local script because the point was to test module scripts and what if I understood it wrong?

Anyways, I would really appreciate some help on this topic. The scripts are below, and here is a video to demonstrate.

game file: burgerissue.rbxl (64.1 KB)

Local Script
Located in StarterPlayerScripts

local uis = game:GetService("UserInputService")
local burgerTable = require(game.ReplicatedStorage.BurgerModuleScript)
local counter = burgerTable.ingredientCounter




uis.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.E and counter < 6 then
		--print("placing bread")
		counter = counter + 1
		burgerTable.cloneBread()

	else return
	
	end

end)

uis.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.R and counter < 6 then
		print("placing cheese")
		counter = counter + 1
		burgerTable.cloneCheese()

	else return

	end

end)

uis.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.F and counter < 6 then
		print("placing meat")
		counter = counter + 1
		burgerTable.cloneMeat()

	else return

	end

end)

uis.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.C and counter < 6 then
		print("placing tomato")
		counter = counter + 1
		burgerTable.cloneTomato()

	else return

	end

end)

uis.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.X and counter < 6 then
		print("placing lettuce")
		counter = counter + 1
		burgerTable.cloneLettuce()

	else return

	end

end)

uis.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.X or input.KeyCode == Enum.KeyCode.C or input.KeyCode == Enum.KeyCode.F or input.KeyCode == Enum.KeyCode.R or input.KeyCode == Enum.KeyCode.E then
		if counter == 5 then
			print("cannot create more bread")
			wait(1.5)
			-- add error function here and finished
			-- make wall cancollide false
			burgerTable.burgerDone()
			counter = 0
		end
		else return
	end

end)

Module Script
Located in Replicated Storage

local module = {
	-- burger
	bread = game.Workspace:WaitForChild("bread"),
	cheese = game.Workspace:WaitForChild("cheese"),
	meat = game.Workspace:WaitForChild("meat"),
	tomato = game.Workspace:WaitForChild("tomato"),
	lettuce = game.Workspace:WaitForChild("lettuce"),
	plate = game.Workspace:WaitForChild("plate"),
	cloneLocation = game.Workspace:WaitForChild("cloneLocation"),
	ingredientCounter = 0,
	itemTable = {},
	
}

module.cloneBread = function()
	local newBread = module.bread:Clone()
	local cloneLocation = module.cloneLocation
	local ingredientCounter = module.ingredientCounter
	local itemTable = module.itemTable
	table.insert(itemTable, newBread)
	newBread.Parent = game.Workspace
	newBread.CFrame = cloneLocation.CFrame * CFrame.new(0,20,0)
	newBread.CFrame = newBread.CFrame * CFrame.Angles(0,0,0)
	
	
end

module.cloneCheese = function()
	local newCheese = module.cheese:Clone()
	local cloneLocation = module.cloneLocation
	local ingredientCounter = module.ingredientCounter
	local itemTable = module.itemTable
	table.insert(itemTable, newCheese)
	newCheese.Parent = game.Workspace
	newCheese.CFrame = cloneLocation.CFrame * CFrame.new(0,20,0)
	newCheese.CFrame = newCheese.CFrame * CFrame.Angles(0,0,0)
end

module.cloneMeat = function()
	local newMeat = module.meat:Clone()
	local cloneLocation = module.cloneLocation
	local ingredientCounter = module.ingredientCounter
	local itemTable = module.itemTable
	table.insert(itemTable, newMeat)
	newMeat.Parent = game.Workspace
	newMeat.CFrame = cloneLocation.CFrame * CFrame.new(0,20,0)
	newMeat.CFrame = newMeat.CFrame * CFrame.Angles(0,0,0)
end

module.cloneTomato = function()
	local newTomato = module.tomato:Clone()
	local cloneLocation = module.cloneLocation
	local ingredientCounter = module.ingredientCounter
	local itemTable = module.itemTable
	table.insert(itemTable, newTomato)
	newTomato.Parent = game.Workspace
	newTomato.CFrame = cloneLocation.CFrame * CFrame.new(0,20,0)
	newTomato.CFrame = newTomato.CFrame * CFrame.Angles(0,0,0)
end

module.cloneLettuce = function()
	local newLettuce = module.lettuce:Clone()
	local cloneLocation = module.cloneLocation
	local ingredientCounter = module.ingredientCounter
	local itemTable = module.itemTable
	table.insert(itemTable, newLettuce)
	newLettuce.Parent = game.Workspace
	newLettuce.CFrame = cloneLocation.CFrame * CFrame.new(0,20,0)
	newLettuce.CFrame = newLettuce.CFrame * CFrame.Angles(0,0,0)
end

module.burgerDone = function()
	local ts = game:GetService("TweenService")
	local itemTable = module.itemTable
	local newPlate = module.plate:Clone()
	local oldPlate = module.plate
	local itemOne = itemTable[1]
	local itemTwo = itemTable[2]
	local itemThree = itemTable[3]
	local itemFour = itemTable[4]
	local itemFive = itemTable[5]
	local itemSix = itemTable[6]
	local itemSeven = itemTable[7]
	local weld1 = Instance.new("WeldConstraint")
	local weld2 = Instance.new("WeldConstraint")
	local weld3 = Instance.new("WeldConstraint")
	local weld4 = Instance.new("WeldConstraint")
	local weld5 = Instance.new("WeldConstraint")
	local weld6 = Instance.new("WeldConstraint")
	oldPlate.Name = "oldPlate"
	newPlate.Name = "plate"
	newPlate.Transparency = 1
	newPlate.Parent = game.Workspace
	print(oldPlate.Name)
	print(newPlate.Name)
	
	weld1.Parent = oldPlate
	weld2.Parent = oldPlate
	weld3.Parent = oldPlate
	weld4.Parent = oldPlate
	weld5.Parent= oldPlate
	weld6.Parent = oldPlate
	
	weld1.Part0 = oldPlate
	weld1.Part1 = itemOne
	weld2.Part0 = oldPlate
	weld2.Part1 = itemTwo
	weld3.Part0 = oldPlate
	weld3.Part1 = itemThree
	weld4.Part0 = oldPlate
	weld4.Part1 = itemFour
	weld5.Part0 = oldPlate
	weld5.Part1 = itemFive
	weld6.Part0 = oldPlate
	weld6.Part1 = itemSix
	

local tweeninfoaway = TweenInfo.new(.4, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
local tweeninfonew = TweenInfo.new(.5, Enum.EasingStyle.Sine, Enum.EasingDirection.In)
	local goalsAway = {
		CFrame = oldPlate.CFrame * CFrame.new(0,0,-50);
	}
	local goalsNew = {
		CFrame = CFrame.new(-28.5, 0.5, 35, 0, 0, 1, 1, 0, 0, 0, 1, 0 )
	}
	local tweenAway = ts:Create(oldPlate, tweeninfoaway, goalsAway)
	local tweenNew = ts:Create(newPlate, tweeninfonew, goalsNew)
	tweenAway:Play()
	wait(1.5)
	itemTable[1]:Destroy()
	itemTable[2]:Destroy()
	itemTable[3]:Destroy()
	itemTable[4]:Destroy()
	itemTable[5]:Destroy()
	itemTable[6]:Destroy()
	newPlate.Transparency = 0
	newPlate.CFrame = newPlate.CFrame * CFrame.new(0,0,50)
	tweenNew:Play()
	newPlate.Name = "plate"
	table.clear(itemTable)
	oldPlate:Destroy()
	

end

return module
2 Likes

this reminds me of a very certain game from 2010

also, how come your Module dosen’t have a return function?

I would also suggest moving it to ServerScriptService and trying what happens.

1 Like

Just checked back on my code, I forgot to add the return function when copying it.
I’ll try moving it and let you know what happens in a minute. Thanks

Third thing: Your first script seems like a little inconsistent.

How come your first script

uis.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.E and counter < 6 then
		--print("placing bread")
		counter = counter + 1
		burgerTable.cloneBread()

	end

end)

dosen’t have else return, but your others (except for the last one) do?

uis.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.R and counter < 6 then
		print("placing cheese")
		counter = counter + 1
		burgerTable.cloneCheese()

	else return

	end

end)

as a side note you can also condense all of the input begans into one input began:

uis.InputBegan:Connect(function(input)
        if input.KeyCode == Enum.KeyCode.E and counter < 6 then
		--print("placing bread")
		counter = counter + 1
		burgerTable.cloneBread()
	else if input.KeyCode == Enum.KeyCode.R and counter < 6 then
		print("placing cheese")
		counter = counter + 1
		burgerTable.cloneCheese()
	else if input.KeyCode == Enum.KeyCode.F and counter < 6 then
		print("placing meat")
		counter = counter + 1
		burgerTable.cloneMeat()
	else if input.KeyCode == Enum.KeyCode.C and counter < 6 then
		print("placing tomato")
		counter = counter + 1
		burgerTable.cloneTomato()
	else if input.KeyCode == Enum.KeyCode.X and counter < 6 then
		print("placing lettuce")
		counter = counter + 1
		burgerTable.cloneLettuce()
       else if counter == 6 then
		print("cannot create more bread")
		wait(1.5)
		-- add error function here and finished
		-- make wall cancollide false
		burgerTable.burgerDone()
		counter = 0
	end
end)

It shows an error when I moved the module script into ServerScriptService.

image_2025-01-26_095120097

Did you change the require() part to say game.ServerScriptStorage.BurgerModuleScript?

Thank you for pointing that out, it seems I missed it when writing the repetitive code. I changed it to include else return.

Yes, the screenshot I sent shows the changed require() part, but for some reason did not work.

I also noticed your “stop” function checks if there are 5 ingredients.
But if you are at 5 ingredients, don’t you want to place another?

EDIT: The condensed code I above is weirdly indented for some reason, although when editing it it appears normal. idk

The first screenshot does not seem to be loading for me

In your ModuleScript, what’s “local itemSeven = itemTable[7]” for? It never seems to be used.

Correct me if I’m wrong, I’ve just got back to this project after a long break, but I think itemTable[7] is the plate.

The plate isn’t ever added to Item Table (as far as I saw).
Try removing that line, maybe that’s the source of the bug?

Thanks. Just tested it out and removed it, still no changes. Maybe its something to do with the names of the parts, and the script is mixing it up?

Give each part a unique name whenever you put it in the table, and see if it fixes it. That shouldn’t be the issue I think, since it stores Instances and afaik instances are unique, but try it.

Wait, I think I found your issue.
After you destroy it the first time (as the item is called plate), that item no longer exists the second time onwards. Hence the WFC will Infinite Yield.

If you rename newPlate to just “plate”, that might fix it.

Where in the script should I rename the part?

Change “newPlate.Name = “newPlate”” to "newPlate.Name = “plate”

Thanks. Just tested and still doesn’t work.

That’s really odd. Is the video you sent earlier still accurate? Or is there different effects now.