function ReplicaController.RequestData()if DataRequestStarted==true then return end DataRequestStarted=true task.spawn(function()while game:IsLoaded()==false do task.wait()end rev_ReplicaRequestData:FireServer()while task.wait(SETTINGS.RequestDataRepeat)do if ReplicaController.InitialDataReceived==true then break end rev_ReplicaRequestData:FireServer()end end)end function ReplicaController.ReplicaOfClassCreated(m,U)if type(m)~="\115\116\114\105\110\103"then error("\091\082\101\112\108\105\099\097\067\111\110\116\114\111\108\108\101\114\093\058 \114\101\112\108\105\099\097\095\099\108\097\115\115 \109\117\115\116 \098\101 \097 \115\116\114\105\110\103")end if type(U)~="\102\117\110\099\116\105\111\110"then error("\091\082\101\112\108\105\099\097\067\111\110\116\114\111\108\108\101\114\093\058 \079\110\108\121 \097 \102\117\110\099\116\105\111\110 \099\097\110 \098\101 \115\101\116 \097\115 \108\105\115\116\101\110\101\114 \105\110 \082\101\112\108\105\099\097\067\111\110\116\114\111\108\108\101\114\046\082\101\112\108\105\099\097\079\102\067\108\097\115\115\067\114\101\097\116\101\100\040\041")end local q=ClassListeners[m]if q==nil then q=Madwork.NewScriptSignal()ClassListeners[m]=q end return q:Connect(U,function()if q:GetListenerCount()==0 and ClassListeners[m]==q then ClassListeners[m]=nil end end)end function ReplicaController.GetReplicaById(m)return Replicas[m]end
-- ReplicaController functions:

function ReplicaController.RequestData() -- Call after all client controllers are loaded and before CoreReadySignal is fired
	if DataRequestStarted == true then
		return
	end
	DataRequestStarted = true
	task.spawn(function() -- In case the initial rev_ReplicaRequestData signal was lost (Highly unlikely)
		while game:IsLoaded() == false do
			task.wait()
		end
		rev_ReplicaRequestData:FireServer()
		while task.wait(SETTINGS.RequestDataRepeat) do
			if ReplicaController.InitialDataReceived == true then
				break
			end
			rev_ReplicaRequestData:FireServer()
		end
	end)
end

function ReplicaController.ReplicaOfClassCreated(replica_class, listener) --> [ScriptConnection] listener(replica)
	if type(replica_class) ~= "string" then
		error("[ReplicaController]: replica_class must be a string")
	end
	if type(listener) ~= "function" then
		error(
			"[ReplicaController]: Only a function can be set as listener in ReplicaController.ReplicaOfClassCreated()"
		)
	end
	-- Getting listener table for replica class:
	local signal = ClassListeners[replica_class]
	if signal == nil then
		signal = Madwork.NewScriptSignal()
		ClassListeners[replica_class] = signal
	end
	return signal:Connect(listener, function()
		-- Cleanup script signals that are no longer used:
		if signal:GetListenerCount() == 0 and ClassListeners[replica_class] == signal then
			ClassListeners[replica_class] = nil
		end
	end)
end

function ReplicaController.GetReplicaById(replica_id)
	return Replicas[replica_id]
end
