--


local characterClone = require(game.ReplicatedStorage.CharacterClone)
local clones = {}

local function onCharacter(character)
	if (character) then
		character.Archivable = true
		character:WaitForChild("Humanoid") -- weird bug
		
		local cloneA = characterClone.new(character)
		local cloneB = characterClone.new(character)
		dualWorld.PortalA:AddToWorld(cloneA.Clone)
		dualWorld.PortalB:AddToWorld(cloneB.Clone)
		table.insert(clones, cloneA)
		table.insert(clones, cloneB)
	end
end

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(onCharacter)
end)

wait(1)

for _, player in next, game.Players:GetPlayers() do
	onCharacter(player.Character)
	player.CharacterAdded:Connect(onCharacter)
end

game:GetService("RunService").RenderStepped:Connect(function(dt)
	for i = 1, #clones do
		clones[i]:Update()
	end
end)
