Reset tycoon when a player leaves the game

How would one go about resetting the tycoon back to its original state when the player leaves the game?
Create a folder that saves the tycoon then is destroyed when the player leaves?

Would something like this work?

game.Players.PlayerRemoving:Connect(function(player)
	local TycoonFolder = game.Workspace.Tycoons
	
	for i,v in pairs(TycoonFolder:GetChildren())do
		if v.Values.OwnerValue.Value == player then
			local TycoonClone = game.ReplicatedStorage:FindFirstChild(v.Name)
			v:Destroy()
			wait()
			TycoonClone.Parent = TycoonFolder
		end
	end
end)

How could I also save the tycoon if the player chooses to come back?

For the destroy function simply do this:

while game:GetService("Players").LocalPlayer.PlayerRemoving do
TycoonFolder:Destroy()

this will destroy it if I’m not wrong, for the saving thing you gotta ask a Programmer

To save, you’ll want to use a datastore. Check out this beginner-friendly guide: Datastore Tutorial for Beginners

To boil this down, you’ll basically want to create a table with booleans for what the player has and hasn’t purchased, as well as their cash value. You create a save function that finds what they do and don’t have in their folder, and set a value to true to incidate that they have unlocked it. Then, another function when the player joins to look through all table values to create the new object if it’s unlocked.

If the tycoon is under a folder, you can destroy the folder and everything in the folder will be removed to clear a tycoon.

Store a value inside the player that is inserted when the player joins and then when their tycoon is either assigned or chosen the value should be renamed to that tycoons value. Then you can have your player removing function be simpler because you get the value that the player had assigned to them and then in your tycoon folder find that value and then reset it:

This will destroy/get rid of the tycoon, but this won’t reset the tycoon back to its state where no one had claimed it. What you can do is to store the default starting tycoon in ReplicatedStorage or ServerStorage and get rid of the tycoon and replace it with the default tycoon once the player leaves using the PlayerRemoving() event.

Or simply make the BasePart (just and example) as the one that is default and eliminate the rest of the Tycoon, thsi way there’s not need for useless memory usage

This could work if the tycoon starts out as a single BasePart as a floor, however, if the tycoon starts out more complex or with more parts to it, it is better to store the default tycoon in ReplicatedStorage or ServerStorage instead.

Yeah, you are right, mine was just an example, also because most of the tycoons I see are mostly 10-5 parts, and if the start of the Tycoon stays there after yous arts building then you could simply store them in a different folder, it if not the. Your method is better

Maybe when the players join clone an unowned Tycoon, when the player leaves parent it to the folder and set it position to the player tycoon position