local O=game:GetService("\087\111\114\107\115\112\097\099\101")local z=game:GetService("\080\108\097\121\101\114\115")local b=game:GetService("\083\116\097\114\116\101\114\080\108\097\121\101\114")local i=game:GetService("\067\111\108\108\101\099\116\105\111\110\083\101\114\118\105\099\101")local X=script.Parent.Parent local y="\080\111\114\116\097\108\067\108\105\101\110\116"local q=b.StarterCharacterScripts:FindFirstChild(y)local M if q==nil then q=Instance.new("\070\111\108\100\101\114")q.Name=y q.Parent=b.StarterCharacterScripts q:SetAttribute("\073\068\067\111\117\110\116\101\114",0)end local h=q:GetAttribute("\073\068\067\111\117\110\116\101\114")+1 q:SetAttribute("\073\068\067\111\117\110\116\101\114",h)local o=Instance.new("\070\111\108\100\101\114")o.Name=h o.Parent=q for O,z in ipairs(script:getChildren())do if true then local O=z:Clone()O.Parent=o if O.ClassName=="\076\111\099\097\108\083\099\114\105\112\116"then O.Disabled=false end end end local c c=O.DescendantRemoving:Connect(function(O)if X==O then o:Destroy()c:Disconnect()for O,z in z:GetChildren()do if not z:IsA("\080\108\097\121\101\114")then continue end;((z.Character:FindFirstChild(y)):FindFirstChild(h)):Destroy()end end end)
local Workspace = game:GetService("Workspace");
local Players = game:GetService("Players");
local StarterPlayer = game:GetService("StarterPlayer");
local CollectionService = game:GetService("CollectionService");
local portal = script.Parent.Parent;

local rootFolderName = "PortalClient";


local rootFolder = StarterPlayer.StarterCharacterScripts:FindFirstChild(rootFolderName);
local idCounter;
if rootFolder == nil then
	rootFolder = Instance.new("Folder");
	rootFolder.Name = rootFolderName;
	rootFolder.Parent = StarterPlayer.StarterCharacterScripts;
	rootFolder:SetAttribute("IDCounter", 0);
end

local currentId = rootFolder:GetAttribute("IDCounter") + 1;
rootFolder:SetAttribute("IDCounter", currentId);

local folder = Instance.new("Folder");
folder.Name = currentId;
folder.Parent = rootFolder;

for _, localObject in ipairs(script:getChildren()) do
	--local shouldClone = (
	--	(not localObject:GetAttribute("IsSingleton")) or
	--	(folder:FindFirstChild(localObject.Name) == nil)
	--);
	if true then
		local newObj = localObject:Clone();
		newObj.Parent = folder;
		if newObj.ClassName == "LocalScript" then
			newObj.Disabled = false;
		end
	end
end

local connection;
connection = Workspace.DescendantRemoving:Connect(function(part) 
	if (portal == part) then
		folder:Destroy();
		connection:Disconnect();
		
		for _, player in Players:GetChildren() do
			if not player:IsA("Player") then
				continue
			end
			
			player.Character:FindFirstChild(rootFolderName):FindFirstChild(currentId):Destroy();
		end
	end
end);
