Elegant way of storing/restoring Tycoon Parts

Hi,

i made the Tycoon tutorial (Part 1,2,3) from the very fine ck Studio+ tutorial and am now trying to make a decent Tycoon.

if anyone is familiar with the code, the parts are arranged like this:
Tycoon
→ Machine
Buy-Script
Purchased Part (folder)

In the Buy Script, the Purchased Part is put in a variable and removed immediatly, and later put back in when it is bought by the player.
So far so good.

But i want to make the Machines upgradeable and the finest way to do this, to put the Upgrade Button in the PurchasedParts Folder, so you only see it when you bought your first upgrade.

Tycoon
→ Machine
Buy-Script
Purchased Part (folder)
----next Buy Script
—next Purchased Part (folder)

Not the tricky part, it took me 2 days till i figured out the reason of the bug.

As the first script copies the whole folder and its subsidaries in a variable, they get restored as planned…BUT the 2nd Level loses its subsidaries, as their Purchased Folders are also stored in Variables when the second Buy-Script runs, but they get deleted when the scripts gets deleted. The scripts are restored but not the variables of course.

So i am looking for a way, to gracefully store the removed parts and folders, to insert them back when they are needed.

i solved it with Boolean Flags, but its rather unpractical, so i thought about Replicated Storage and Data Stores, but would really appreciate a hint on how to better solve this.

I have not seen the tutorial and I don’t understand what the exact issue is but I’ll try to answer it with the assumptions that you are referring to restoring the tycoons machines after a player rejoins the game.

The most simplest method would be to simply keep track of what machines the player has bought, since from what I can understand you have a player buy a machine “upgrade” by simply buying another entity/machine, you can just create a table with all the machines the player has bought. With that you can read the data by simply checking if the player has bought that object and then have the game just spawn the machine.

1 Like

Thank you, but this leaves me with the problem, where to store and retrieve the Tycoon parts, though i guess i should put them in Replicated Storage then. Would mean a complete revamp of the machine distribution though.

But the core of the problem is the same: If i put all the parts in ReplicatedStorage, i would need to retrieve them one by one by their exact name. So on every machine i would need to code the correct Parts. Right now this works only through the folder structure of the tycoon.

And on the other side, i would need to store(?) the attachment-locations, so where to put the retrieved Parts. Who is the fitting parent?

I had a quick glance at the tutorial, I had no surprises with how it misses and ignores alot of what I consider to be essential fundamentals in scripting. Now for the solution to your topic, the best way to store the parts for the tycoon is in the ReplicatedStorage, have the script inside be Disabled and be re-enabled by the purchase button script. Now to do this you need to setup your machines in a way that they have a PrimaryPart, this root part is what you will use to orientate the entire model when using :SetPrimaryPartCFrame() and you will simply match it with the tycoons position by having an invisible alignment part in the tycoon. Do not forget to clone it, so other tycoons can use the same entity.

And just some heads up, :SetPrimaryPartCFrame() is not a good method to use due to the floating error, however for the purpose of using it once over a couple of times means that the parts should still be fine and as long as you are not using it over and over again and do not require precision, if so this method has to be the most simplest to do.

i really appreciate your feedback and understand the plan. But for now i think I will keep going with the “Boolean”-Solution. So every path has a boolean check, if its the right time when the Sub-Parts should be deleted, which is when they are not yet to be shown.

i had the thought that on the long way this is no good way to store the parts, but i will use an autosave to prevent errors from disconnecting player.

Anyway thank you and for watching the tutorial :slight_smile: