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

Is there a better way to do this?

I am removing each part of the tycoon that the player purchases to have it replaced in the game later. My problem is that I am doing this one by one. This is a tedious task and is taking way to long. Is there a better way?

This is currently what I am doing.

local tycoon = script.Parent.Parent

local dirt = tycoon.Purchases.DirtDropper:Clone()
dirt:Destroy()

local stone = tycoon.Purchases.StoneDropper:Clone()
stone:Destroy()

local copper = tycoon.Purchases.CopperDropper:Clone()
copper:Destroy()

I was thinking of doing local clone = tycoon.Purchases:GetChildren():Clone() This would be a quick way to remove everything but when it came time to purchase an object all the parts would be re-added all at once. Right?

Thanks for the help ahead of time.

4 comments

0

The script you are showing destroys those objects immediately before they are actually parented to anything. If they all have the same parent, you can call ClearAllChildren on that.

0

I can do that. However, if I do that I cannot reparent them one at a time as they are purchased. Am I right?

0

What are you using to get the purchased? Like do they touch a part or do they press some type of button? What are you doing to get them purchased?

0

@KingLoneCat They touch a button.

1 answer

✓ Accepted answer

You're problem is that, the thing about :Clone() it needs to have a parent as well I create holo commands for groups, and to make the map simulation I have to clone it,

here is an example.

local map = game.ServerStorage.Map
x = map:Clone()
x.Parent = game.Workspace

that was an example, now let me help you out with your problem.

local tycoon = script.Parent.Parent

local dirt = tycoon.Purchases.DirtDropper
x=dirt:Clone()
dirt:Destroy()
-- extra code here for "x"

local stone = tycoon.Purchases.StoneDropper
s = stone:Clone()
stone:Destroy()
-- extra code here for "s"

local copper = tycoon.Purchases.CopperDropper
n = copper:Clone()
copper:Destroy()
--extra code here for "n"

I hope this fixes your problem, Have a nice day!

2 comments

0

By the way, I left out the ".Parent" portion as you are obviously doing a tycoon, and you need to add more functions or you might need to, I don't know for sure so I left them out, they are easy to add in though.

0

I know that clones need to have a parent as well. The clones are parented when the player purchases them. Until then they are removed and their parents are nil. I found an alternative solution now. Since your answer is the only one here I will accept it. Thanks for try anyway.

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