Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I copy a part that I have instead of making a new part?

I am trying to make a tycoon with droppers, a specific dropper has the following code inside it:

wait(2)
workspace:WaitForChild("PartStorage")

while true do
	wait(1.5) -- How long in between drops
	local part = Instance.new("Part",workspace.PartStorage)
	part.BrickColor=script.Parent.Parent.Parent.DropColor.Value
	part.Material=script.Parent.Parent.Parent.MaterialValue.Value
	local cash = Instance.new("IntValue",part)
	cash.Name = "Cash"
	cash.Value = 5 -- How much the drops are worth
	part.CFrame = script.Parent.Drop.CFrame - Vector3.new(0,1.4,0)
	part.FormFactor = "Custom"
	part.Size=Vector3.new(1.2, 1.2, 1.2) -- Size of the drops
	part.TopSurface = "Smooth"
	part.BottomSurface = "Smooth"
	game.Debris:AddItem(part,20) -- How long until the drops expire
end

My question is; how would I change this script so that it copies the part located at script.Parent.DropPart instead of creating an entirely new part?

I am new to Roblox lua so explanations in detail would be helpful, thanks!

1 answer

✓ Accepted answer

Use the Clone() function to return a copy of the object.

In your case, it would look something like this:

local Clone = script.Parent.DropPart:Clone() -- Copies the part
Clone.Parent = game.Workspace -- Parents it to the workspace

If this answers your question, please mark this as the best answer!

3 comments

0

One more thing, how would this look inside of my script? Hope that isn't to much to ask but it would be helpful, thanks!

0

Put it anywhere inside the while loop. It doesn't matter where as long as it's inside the loop.

0

Alrighty, thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.