Is it possible to make the map refresh?

Hey, its me again so basically.

I want to make a script that basically refreshes the entire map after a shutdown/meltdown on my core game.

Basically this is what I had in my mind or the list of events thats going to occur:

1.Integridy drops to 0
2.Meltdown
3.Shutdown(If it works, refresh)
4.Boom
5.Refresh

Any help would be appriciated.

2 Likes

You could save the map as a model or list/folder of models in ServerStorage, let the game destroy the current one, then clone the fresh map back into workspace.

This is amazing and all but how do I make the script that does this.

Even though my tag claims that I am a dev I only know how to place ifs and elses.

Any tutorials or can you guide me through this?

Because you are still learning programming, the Onboarding experience might be something you want to take a look at. It has plenty of tutorials for learning Roblox’s development platform and game engine.

Here’s a simple function that can unload the current map and load a new one map, although it’s untested so it may not work. It may have anything from a minor typo to a major overlook or flaw. Also, if you don’t understand how parts of it work that is okay. You will just have to learn enough to understand what it’s doing. You can check out the Onboarding experience like I mentioned or find tutorials on youtube. If you want to use youtube tutorials, I recommend AlvinBlox or TheDevKing, as I’ve found each to be most useful in the past while I was still learning. I’ll also provide some youtube videos at the bottom of this reply.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local function anchorCharacters(anchor, list)
	for _, player in pairs(Players:GetPlayers()) do
		local character = player.Character
		
		if character then
			if list then
				table.insert(list, character)
			end
			
			character.PrimaryPart.Anchored = anchor
		end
	end
end

local function loadMap(map)
	local blacklist = {}
	anchorCharacters(true, blacklist)
	
	for _, child in pairs(workspace:GetChildren()) do -- if you don't want to filter the children then you can just use Instance:ClearAllChildren
		if not table.find(blacklist, child) then
			child:Destroy()
		end
	end
	map:Clone().Parent = workspace
	
	anchorCharacters(false)
end
  • Note: Keep in mind that the map variable should be a Folder containing everything you want to be in the map be default. Also, the folder containing the map should be placed in ReplicatedStorage.
  • Note2: if you don’t want to filter the children then you can just use Instance:ClearAllChildren instead of the for loop in the loadMap function.



This last one is just Roblox tutorials in general.

Thanks bro I will check these and test the code soon.