-- Written by GFink. 
-- This script can be placed anywhere.

local y=workspace:GetDescendants()
local r

for s=1,#y do
	if y[s].Name=="Doomspires" then
		local sa=y[s]:GetChildren()
		local m=Instance.new("Model")
		m.Name="Backup"
		m.Parent=game.ServerStorage
		for i=1,#sa do
			if sa[i].Name~="GameValues" then
				if not sa[i]:IsA("Script") then
					sa[i]:Clone().Parent=m
				end
			end
		end
		script.Signal.Changed:connect(function(Property)
			if Property==true then
				print("Regenerating")
				local ab=y[s]:GetChildren()
				for cd=1,#ab do
					if not ab[cd]:IsA("Script") then
						ab[cd]:Destroy()
					end
				end
				script.GameControlScriptLocation.Value.Disabled=true
				local z=game.ServerStorage:WaitForChild("Backup",1):GetChildren()
				for f=1,#z do
					z[f]:Clone().Parent=y[s]
				end
				script.GameControlScriptLocation.Value.Disabled=false
				script.Signal.Value=false
				
				y[s]:MakeJoints()
				
				local t=game.Teams:GetChildren()
				for d=1,#t do
					if t[d].Name~="Spectators" then
						t[d].AutoAssignable=true
					end
				end
				
				script.GameControlScriptLocation.Value.ShuffleTeams:Invoke()
				script.GameControlScriptLocation.Value.BalanceTeams:Invoke()
				
				wait(1)
				
				local p=game.Players:GetDescendants()
				for q=1,#p do
					if p[q].Parent then
						if p[q].Parent.Name=="leaderstats" then
							p[q].Value=0
						end
					end
					if p[q]:IsA("Player") then
						game:GetService("ReplicatedStorage").ChangeTeamEvent:FireClient(p[q],p[q].TeamColor) -- i could use fireallclients but then i couldnt select the teamcolor property
						p[q]:LoadCharacter()
						p[q]:WaitForChild("AntiTeamKill",5).Value=true
					elseif p[q]:IsA("TextButton") then -- only works in experimental mode
						if p[q].Name=="Button" then
							p[q].Visible=false
						end
					end
				end

			elseif Property==false then
				return
			end
		end)
	end
end
