function GlobalUpdates.ListenToNewActiveUpdate(K,t)if type(t)~="\102\117\110\099\116\105\111\110"then error("\091\080\114\111\102\105\108\101\083\101\114\118\105\099\101\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 \071\108\111\098\097\108\085\112\100\097\116\101\115\058\076\105\115\116\101\110\084\111\078\101\119\065\099\116\105\118\101\085\112\100\097\116\101\040\041")end local s=K._profile if K._update_handler_mode==true then error("\091\080\114\111\102\105\108\101\083\101\114\118\105\099\101\093\058 \067\097\110\'\116 \108\105\115\116\101\110 \116\111 \110\101\119 \103\108\111\098\097\108 \117\112\100\097\116\101\115 \105\110 \080\114\111\102\105\108\101\083\116\111\114\101\058\071\108\111\098\097\108\085\112\100\097\116\101\080\114\111\102\105\108\101\065\115\121\110\099\040\041")elseif K._new_active_update_listeners==nil then error("\091\080\114\111\102\105\108\101\083\101\114\118\105\099\101\093\058 \067\097\110\'\116 \108\105\115\116\101\110 \116\111 \110\101\119 \103\108\111\098\097\108 \117\112\100\097\116\101\115 \105\110 \118\105\101\119 \109\111\100\101")elseif s:IsActive()==false then return{Disconnect=function() end}end return K._new_active_update_listeners:Connect(t)end function GlobalUpdates.ListenToNewLockedUpdate(K,t)if type(t)~="\102\117\110\099\116\105\111\110"then error("\091\080\114\111\102\105\108\101\083\101\114\118\105\099\101\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 \071\108\111\098\097\108\085\112\100\097\116\101\115\058\076\105\115\116\101\110\084\111\078\101\119\076\111\099\107\101\100\085\112\100\097\116\101\040\041")end local s=K._profile if K._update_handler_mode==true then error("\091\080\114\111\102\105\108\101\083\101\114\118\105\099\101\093\058 \067\097\110\'\116 \108\105\115\116\101\110 \116\111 \110\101\119 \103\108\111\098\097\108 \117\112\100\097\116\101\115 \105\110 \080\114\111\102\105\108\101\083\116\111\114\101\058\071\108\111\098\097\108\085\112\100\097\116\101\080\114\111\102\105\108\101\065\115\121\110\099\040\041")elseif K._new_locked_update_listeners==nil then error("\091\080\114\111\102\105\108\101\083\101\114\118\105\099\101\093\058 \067\097\110\'\116 \108\105\115\116\101\110 \116\111 \110\101\119 \103\108\111\098\097\108 \117\112\100\097\116\101\115 \105\110 \118\105\101\119 \109\111\100\101")elseif s:IsActive()==false then return{Disconnect=function() end}end return K._new_locked_update_listeners:Connect(t)end function GlobalUpdates.LockActiveUpdate(K,t)if type(t)~="\110\117\109\098\101\114"then error("\091\080\114\111\102\105\108\101\083\101\114\118\105\099\101\093\058 \073\110\118\097\108\105\100 \117\112\100\097\116\101\095\105\100")end local s=K._profile if K._update_handler_mode==true then error("\091\080\114\111\102\105\108\101\083\101\114\118\105\099\101\093\058 \067\097\110\'\116 \108\111\099\107 \097\099\116\105\118\101 \103\108\111\098\097\108 \117\112\100\097\116\101\115 \105\110 \080\114\111\102\105\108\101\083\116\111\114\101\058\071\108\111\098\097\108\085\112\100\097\116\101\080\114\111\102\105\108\101\065\115\121\110\099\040\041")elseif K._pending_update_lock==nil then error("\091\080\114\111\102\105\108\101\083\101\114\118\105\099\101\093\058 \067\097\110\'\116 \108\111\099\107 \097\099\116\105\118\101 \103\108\111\098\097\108 \117\112\100\097\116\101\115 \105\110 \118\105\101\119 \109\111\100\101")elseif s:IsActive()==false then error("\091\080\114\111\102\105\108\101\083\101\114\118\105\099\101\093\058 \080\082\079\070\073\076\069 \069\088\080\073\082\069\068 - \067\097\110\'\116 \108\111\099\107 \097\099\116\105\118\101 \103\108\111\098\097\108 \117\112\100\097\116\101\115")end local o=nil for K,s in ipairs(K._updates_latest[2])do if s[1]==t then o=s break end end if o~=nil then local s=false for K,o in ipairs(K._pending_update_lock)do if t==o then s=true break end end if s==false and o[3]==false then table.insert(K._pending_update_lock,t)end else error("\091\080\114\111\102\105\108\101\083\101\114\118\105\099\101\093\058 \080\097\115\115\101\100 \110\111\110-\101\120\105\115\116\097\110\116 \117\112\100\097\116\101\095\105\100")end end function GlobalUpdates.ClearLockedUpdate(K,t)if type(t)~="\110\117\109\098\101\114"then error("\091\080\114\111\102\105\108\101\083\101\114\118\105\099\101\093\058 \073\110\118\097\108\105\100 \117\112\100\097\116\101\095\105\100")end local s=K._profile if K._update_handler_mode==true then error("\091\080\114\111\102\105\108\101\083\101\114\118\105\099\101\093\058 \067\097\110\'\116 \099\108\101\097\114 \108\111\099\107\101\100 \103\108\111\098\097\108 \117\112\100\097\116\101\115 \105\110 \080\114\111\102\105\108\101\083\116\111\114\101\058\071\108\111\098\097\108\085\112\100\097\116\101\080\114\111\102\105\108\101\065\115\121\110\099\040\041")elseif K._pending_update_clear==nil then error("\091\080\114\111\102\105\108\101\083\101\114\118\105\099\101\093\058 \067\097\110\'\116 \099\108\101\097\114 \108\111\099\107\101\100 \103\108\111\098\097\108 \117\112\100\097\116\101\115 \105\110 \118\105\101\119 \109\111\100\101")elseif s:IsActive()==false then error("\091\080\114\111\102\105\108\101\083\101\114\118\105\099\101\093\058 \080\082\079\070\073\076\069 \069\088\080\073\082\069\068 - \067\097\110\'\116 \099\108\101\097\114 \108\111\099\107\101\100 \103\108\111\098\097\108 \117\112\100\097\116\101\115")end local o=nil for K,s in ipairs(K._updates_latest[2])do if s[1]==t then o=s break end end if o~=nil then local s=false for K,o in ipairs(K._pending_update_clear)do if t==o then s=true break end end if s==false and o[3]==true then table.insert(K._pending_update_clear,t)end else error("\091\080\114\111\102\105\108\101\083\101\114\118\105\099\101\093\058 \080\097\115\115\101\100 \110\111\110-\101\120\105\115\116\097\110\116 \117\112\100\097\116\101\095\105\100")end end

function GlobalUpdates:ListenToNewActiveUpdate(listener) --> [ScriptConnection] listener(update_id, update_data)
	if type(listener) ~= "function" then
		error("[ProfileService]: Only a function can be set as listener in GlobalUpdates:ListenToNewActiveUpdate()")
	end
	local profile = self._profile
	if self._update_handler_mode == true then
		error("[ProfileService]: Can't listen to new global updates in ProfileStore:GlobalUpdateProfileAsync()")
	elseif self._new_active_update_listeners == nil then
		error("[ProfileService]: Can't listen to new global updates in view mode")
	elseif profile:IsActive() == false then -- Check if profile is expired
		return { -- Do not connect listener if the profile is expired
			Disconnect = function() end,
		}
	end
	-- Connect listener:
	return self._new_active_update_listeners:Connect(listener)
end

function GlobalUpdates:ListenToNewLockedUpdate(listener) --> [ScriptConnection] listener(update_id, update_data)
	if type(listener) ~= "function" then
		error("[ProfileService]: Only a function can be set as listener in GlobalUpdates:ListenToNewLockedUpdate()")
	end
	local profile = self._profile
	if self._update_handler_mode == true then
		error("[ProfileService]: Can't listen to new global updates in ProfileStore:GlobalUpdateProfileAsync()")
	elseif self._new_locked_update_listeners == nil then
		error("[ProfileService]: Can't listen to new global updates in view mode")
	elseif profile:IsActive() == false then -- Check if profile is expired
		return { -- Do not connect listener if the profile is expired
			Disconnect = function() end,
		}
	end
	-- Connect listener:
	return self._new_locked_update_listeners:Connect(listener)
end

function GlobalUpdates:LockActiveUpdate(update_id)
	if type(update_id) ~= "number" then
		error("[ProfileService]: Invalid update_id")
	end
	local profile = self._profile
	if self._update_handler_mode == true then
		error("[ProfileService]: Can't lock active global updates in ProfileStore:GlobalUpdateProfileAsync()")
	elseif self._pending_update_lock == nil then
		error("[ProfileService]: Can't lock active global updates in view mode")
	elseif profile:IsActive() == false then -- Check if profile is expired
		error("[ProfileService]: PROFILE EXPIRED - Can't lock active global updates")
	end
	-- Check if global update exists with given update_id
	local global_update_exists = nil
	for _, global_update in ipairs(self._updates_latest[2]) do
		if global_update[1] == update_id then
			global_update_exists = global_update
			break
		end
	end
	if global_update_exists ~= nil then
		local is_pending_lock = false
		for _, lock_update_id in ipairs(self._pending_update_lock) do
			if update_id == lock_update_id then
				is_pending_lock = true -- Exclude global updates pending to be locked
				break
			end
		end
		if is_pending_lock == false and global_update_exists[3] == false then -- Avoid id duplicates in _pending_update_lock
			table.insert(self._pending_update_lock, update_id)
		end
	else
		error("[ProfileService]: Passed non-existant update_id")
	end
end

function GlobalUpdates:ClearLockedUpdate(update_id)
	if type(update_id) ~= "number" then
		error("[ProfileService]: Invalid update_id")
	end
	local profile = self._profile
	if self._update_handler_mode == true then
		error("[ProfileService]: Can't clear locked global updates in ProfileStore:GlobalUpdateProfileAsync()")
	elseif self._pending_update_clear == nil then
		error("[ProfileService]: Can't clear locked global updates in view mode")
	elseif profile:IsActive() == false then -- Check if profile is expired
		error("[ProfileService]: PROFILE EXPIRED - Can't clear locked global updates")
	end
	-- Check if global update exists with given update_id
	local global_update_exists = nil
	for _, global_update in ipairs(self._updates_latest[2]) do
		if global_update[1] == update_id then
			global_update_exists = global_update
			break
		end
	end
	if global_update_exists ~= nil then
		local is_pending_clear = false
		for _, clear_update_id in ipairs(self._pending_update_clear) do
			if update_id == clear_update_id then
				is_pending_clear = true -- Exclude global updates pending to be cleared
				break
			end
		end
		if is_pending_clear == false and global_update_exists[3] == true then -- Avoid id duplicates in _pending_update_clear
			table.insert(self._pending_update_clear, update_id)
		end
	else
		error("[ProfileService]: Passed non-existant update_id")
	end
end
