Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 7 years ago

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

Log in to vote
1
Answered by
cfiredog 274 Moderation Voter
7 years ago

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!

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! SambaLover 16 — 7y
0
Put it anywhere inside the while loop. It doesn't matter where as long as it's inside the loop. cfiredog 274 — 7y
0
Alrighty, thanks! SambaLover 16 — 7y
Ad

Answer this question