Script / Value regeneration system

  1. What do you want to achieve?
    Hello, so im trying to do a system that regenarate the server.
    I use collection service, if an object is tagged “Resetable” i want it to be saved and after that when i want i can trigger the regen system that remove the original object and replace it with the saved object.
    (Im sorry i don’t know how can i explain it if you have more questions you can ask)

  2. What is the issue?
    I can’t manage to do it.

  3. What solutions have you tried so far?
    I tried myself, looked on forums.

  1. If you want to regenerate the entire map, you need to move the main things (which interact during the game) to a folder that you will create in Workspace and name it somehow. Then you also need to create a folder for the values that are in the ‘Workspace’.

Now all you need to do is copy this folder and second folder for values from Workspace and paste it into ServerStorage in a folder called ‘MapRegen’. (Only it needs to be copied by the server when starting the game)

game.Workspace.Folder:Clone().Parent=game.ServerStorage.MapRegen
game.Workspace.SecondFolder:Clone().Parent=game.ServerStorage.MapRegen

All you need to do is copy this folder from ServerStorage and move it to Workspace, but don’t forget to delete the old folder and second old folder for values

game.Workspace.Folder:Destroy()
game.Workspace.SecondFolder:Destroy()

game.ServerStorage.MapRegen.Folder:Clone().Parent=game.Workspace
game.ServerStorage.MapRegen.SecondFolder:Clone().Parent=game.Workspace
  1. Disabling scripts
    You will have to transfer all the scripts to the ServerScriptService for this and separate them into two parts, 1. The scripts that are responsible for the server, the purchase of the item, etc. (Be sure that the scripts are not related to the Workspace folder and second folder for values in any way (except regeneration script), otherwise it may give an error). 2. Scripts that are responsible for this folder (for example, a player presses a button and the door opens and this door is in the folder Workspace).

All you have to do is stop the scripts that are responsible for the folder and second folder in Workspace and run them again at the end of regeneration

Result:

game.Workspace.Folder:Clone().Parent=game.ServerStorage.MapRegen
game.Workspace.SecondFolder:Clone().Parent=game.ServerStorage.MapRegen

game.ReplicatedStorage.Regen.Event:Connect(function()
  for i,v in pairs(game.ServerScriptService.ResponsingScripts:GetDescendants()) do
     if v.ClassName=="Script" then
        v.Disabled=true
     end
  end

  game.Workspace.Folder:Destroy()
  game.Workspace.SecondFolder:Destroy()

  game.ServerStorage.MapRegen.Folder:Clone().Parent=game.Workspace
  game.ServerStorage.MapRegen.SecondFolder:Clone().Parent=game.Workspace
  
  for i,v in pairs(game.ServerScriptService.ResponsingScripts:GetDescendants()) do
     if v.ClassName=="Script" then
        v.Disabled=false
     end
  end
end)

Call game.ReplicatedStorage.Regen:Fire() to regenerate your map. Don’t forget add ‘BindableEvent’ in ReplicatedStorage and name it ‘Regen’

You will have to recode the entire or partly game for this process

I hope I helped you somehow and you understood at least a little what I wrote in this post, if you did not understand, re-read it again until you understand

Thank you so much for your help !