[SOLVED] I need a script to reset the entire workspace

sorry its not a folder, its a table, it doesnt need to be stored anywhere, sorry i should’ve named the variable something else

oh thats fine, just didnt know im a beginner

i presume the first part runs at server startup, and this part (second part) runs at the explosion?

-- after the explosion, you can destroy everything from the workspace (except for the players), and then you go through the folder table and parent everything to the workspace.
for i, v in ipairs(workspace:GetChildren()) do
	if v.Name == 'Terrain' or v.Name == 'Camera' or game.Players:GetPlayerFromCharacter(v) then continue end
	v:Destroy()
end

for i, v in ipairs(folder) do
	v.Parent = workspace
end
1 Like

i just saw “folder” in the script and thought it was a folder

1 Like

after the explosion, yes

char limit

alright, ill paste this into a workspace script to run at the start, and ill test it using a part

1 Like

are you supposed to take this part and paste it into the second half? (im testing it using 2 different scripts)

local folder = {}
1 Like
local clickDetector = workspace.ClickDetectorPart.ClickDetector
local resetFolder = Instance.new("Folder")

resetFolder.Parent = game:GetService("ServerStorage")

for index, value in pairs(workspace:GetChildren()) do

	if not value:IsA("Camera") and not value:IsA("Terrain") and not value:FindFirstChild("Humanoid") then

		local clonedInstance = value:Clone()
		clonedInstance.Parent = resetFolder

	end

end

clickDetector.MouseClick:Connect(function()
	
for index, value in pairs(workspace:GetChildren()) do

		if not value:IsA("Camera") and not value:IsA("Terrain") and not value:FindFirstChild("Humanoid") then

		value:Destroy()

	end

end

for index, value in pairs(resetFolder:GetChildren()) do

	local clonedValue = value:Clone()
	clonedValue.Parent = workspace

end
		
		script.Enabled = false
	script.Enabled = true	
	
end)

Cloning inside the Workspace and reseting this Script.

im testing moorans solution right now, if it doesnt work, ill test this one

this solution for me cleared the map, but never loaded it back in

it worked for me, can you show me how you’ve constructed it?

ill provide images

char limit

1 Like

Wait lo


im testing moorans solution rn, not yours, sorry

image

since your using two different scripts you can create a folder inside of serverStorage and do the same thing, because your storing an empty table, so try this:

-- create a folder before startup that stores everything from the workspace
local folder = Instance.new('Folder', game.ServerStorage)
folder.Name = 'CopiedMap'

for i, v in ipairs(workspace:GetChildren()) do
	if v.Name == 'Terrain' or v.Name == 'Camera' or game.Players:GetPlayerFromCharacter(v) then continue end
	local cloned = v:Clone()
	cloned.Parent = folder
end


-- (second script)
local copiedMap = game.ServerStorage:FindFirstChild('copiedMap')

if copiedMap then
	for i, v in ipairs(workspace:GetChildren()) do
		if v.Name == 'Terrain' or v.Name == 'Camera' or game.Players:GetPlayerFromCharacter(v) then continue end
		v:Destroy()
	end

	for i, v in ipairs(folder) do
		v.Parent = workspace
	end
end

in the second script, “folder” has an orange line underneath it

1 Like

oh my bad, change “folder” to “copiedMap”

local clickDetector = workspace.ClickDetectorPart.ClickDetector
local resetFolder = Instance.new("Folder")

resetFolder.Parent = game:GetService("ServerStorage")

for index, value in pairs(workspace:GetChildren()) do

	if not value:IsA("Camera") and not value:IsA("Terrain") and not value:FindFirstChild("Humanoid") then

		local clonedInstance = value:Clone()
		clonedInstance.Parent = resetFolder

	end

end

clickDetector.MouseClick:Connect(function()
	
for index, value in pairs(workspace:GetChildren()) do

		if not value:IsA("Camera") and not value:IsA("Terrain") and not value:FindFirstChild("Humanoid") then

		value:Destroy()

	end

end

for index, value in pairs(resetFolder:GetChildren()) do

	local clonedValue = value:Clone()
	clonedValue.Parent = workspace

end
		
		script.Enabled = false
	script.Enabled = true	
	
end)

fails to clear the map
image

1 Like

Olm der arme