How do I reset a tycoon when the player leaves?

Hi, I wanted to know how to reset a tycoon when a player leaves the game. Heres the door script if it helps:

local Owner = script.Parent.Parent.Owner
local Owned = script.Parent.Parent.Owned
local Plot = script.Parent.Parent.Parent
local TycoonDoor1 = script.Parent
local debounce = false
script.Parent.Touched:Connect(function(hit)
	if debounce == false then
		if hit.Parent:FindFirstChild("Humanoid")then
			if Owned.Value == false then
				local plr = game.Players:FindFirstChild(hit.Parent.Name)
				local label = script.Parent.Tycoon_OwnerName.Tycoon_OwnerNameLabel
				label.Text = plr.Name.."'s Tycoon"
				Owner.Value = plr.Name
				Owned.Value = true
				print(Plot.Name.." was claimed by "..plr.Name..".")
				TycoonDoor1.CanCollide = false
				Plot.Sign.TextDisplay.SurfaceGui.TextLabel.Text = plr.Name.."'s Tycoon"
			else
				print("Plot is already owned!")
			end
		end
		debounce = true
		wait(0.5)
		debounce = false
	end
end)

You have multiple ways you could do this. Either you destroy everything within a group or folder, or anything that has been tagged via CollectionService. You could execute either method using a Players.PlayerRemoving event and a for loop which runs through either type of array.

So do I make a folder called “PurchasedItems” and everything that isn’t on the tycoon by default is in that folder? Then when the player leaves loop through the folder and destroy everything in it?

I would probably make a folder for all the tycoons purchased items which could contain anything replicated via gameplay by the player. I would then organise it by player so each player gets their own folder. Once the player leaves and you have saved their data you could then either delete the folder or everything inside the folder.

2 Likes