Restore a server to its default place

Basically, is there a way to revert all the changes made by any scripts and general roblox stuff like physics and then re-run the scripts again?

For example, if I have a script that makes some changes to the place, e.g.

-- Random stuff inside a script

local part = Instance.new("Part", workspace)
part.Size = Vector3.new(5,10,8)
part.Anchored = true
part.Position = Vector3.new(math.random(1,5), 10, math.random(1, 9))

workspace:SetAttribute("myAttribute", CFrame.new())

game.Lighting.Atmosphere.Density = 0.6

workspace.RandomSound:Play()

require(randomModuleID)

_G.test = function() 
    print("hello world!") 
end)

game.Players.PlayerAdded:Connect(function(player)
    print(player, "Joined!")
    player:SetAttribute("joined", true)
end)

Is there a way to revert everything and restore the place to its original state? I understand that stopping the game and re-teleporting all the players works but is there another way?

You can put everything in folders and have a script clone them, and when you want to revert everything, just delete the current folders and put the clones in their place

(make sure to have the reverter script be outside of the folders)

Yes but it wouldn’t revert the changes? For my use-case I would like it to have the functionality of creating a new server without the players having to leave the server and connect to the new one.

Sadly, there is no official way. What you could do is turn the entire script to a function which you could run and parent everything to a folder named “CurrentServer”. Whenever you want to return the server back you could call the function and in the function It would check if there is a folder named “CurrentServer” and you would destroy it if it exists.