How can I make my map regenerate?

Hello. I made a deathrun map with traps that only work once. I want the players to be able to play the game over, however. How can I make it so the map somehow destroys itself after the game is over but regenerate itself in its original state when the game starts up again? I can give info about the map and game as a whole if you need me to.

I know this is probably a really easy question to be asked and whatnot, but I couldn’t find any suitable tutorials on here, youtube, or the dev hub. If you find a good tutorial let me know, but any help would be greatly appreciated!

1 Like

You can put the first version of the map in Server storage, and once you need the map, :Clone it and set its parent to Workspace. Once the game is over, you can :Destroy() it.

2 Likes

Hello! Sorry for long response.

I got an error in the output. It said:

" The Parent property of duplex is locked, current parent: NULL, new parent Workspace"

Try checking the locked property of the model.

This might help too: BasePart | Documentation - Roblox Creator Hub.

1 Like
workspace.LoadedMap:Clone().Parent = game:GetService("ServerStorage")
workspace.LoadedMap:Destroy()
game:GetService("ServerStorage").LoadedMap:Clone().Parent = workspace

This relies on the map being one model.

2 Likes

I put that script inside the map model, but still got the error. If this helps, the map model had many models inside of it.

That error usually comes from destroying something too quickly after a re-parent. The only fix I know for this is wait()ing before :Destroy()ing.

1 Like

The map is created, played on, then destroyed. I put a wait() anyway but it didn’t work. It just got stuck on intermission and didn’t clone the map again. It would clone the map the first time but wouldn’t clone after being destroyed.

add print()s to see what might be wrong, or if their are errors

2 Likes

Place the map in serverstorage (make sure it’s all in one model/group), and clone it to the workspace each time you want to use it, then delete it when you don’t need to use it.

local Map = game.ServerStorage.MapNameHere

while true do
     wait(10)
     local Clone = Map:Clone()
     Clone.Parent = game.Workspace
     wait(5)
     Clone:Destroy()
end

I don’t know for sure if that’d work, but I believe you’d do something like I just did - except you put it in the workspace when the round starts, destroy it when the round ends.

2 Likes

For some reason that did not work either :confused:

Errors? Also is your map in a model?

1 Like

there were no errors, the game just didn’t function. I do run a fairly complex round system if you need to see the whole script.

My map is in a model which I stored in ServerStorage.

You might want to check this if it’s malfunctioning. If you did so, sorry for my incomprehension.

1 Like

I don’t know what I did but I solved it. I guess I just needed to sharpen my knowledge of cloning and lighting and all that. Thank you all for your contributions!

1 Like