[HELP] Why is this Global Notification script not working?

This is suppose to send notifications to all players in the entire game in all servers, but in the Output it says: ServerScriptService.SFramework.Notification:103: invalid argument #1 to ‘pairs’ (table expected, got nil)

Why is it showing invalid argument #1 to ‘pairs’ and how do I fix that?

local stores = game:GetService(‘DataStoreService’)
local globalNotificationStore = DataShard(‘Notification’)

local serverLaunchTime = os.time()
local globalNotificationsRead = {}

if globalNotificationStore then
globalNotificationStore:OnUpdate(‘Inbox’, function(list)
for _, n in pairs(list) do
if n.ts > serverLaunchTime and not globalNotificationsRead[n.id] then
globalNotificationsRead[n.id] = true
globalNotificationReceived(n)
end
end
end)
end

local stores = game:GetService(‘DataStoreService’)
local globalNotificationStore = DataShard(‘Notification’)

local serverLaunchTime = os.time()
local globalNotificationsRead = {}

if globalNotificationStore then
   globalNotificationStore:OnUpdate(‘Inbox’, function(list)
   for _, n in pairs(list) do
      if n.ts > serverLaunchTime and not globalNotificationsRead[n.id] then
          globalNotificationsRead[n.id] = true
          globalNotificationReceived(n)
      end
    end
  end)
end

This is just to help others read it, in a better format.

1 Like

Also, what is list? Do you have a table called list?

If you’re trying to display a global notification, please use messagingservice. MessagingService | Documentation - Roblox Creator Hub

I re-wrote your code as best as I could to use MessagingService. I’ve also included an example of how to use this. OnUpdate is deprecated in favor of MessagingService, so you should move to this.

Code using MessagingService
local messagingService = game:GetService("MessagingService")
local serverLaunchTime = os.time()
local globalNotificationsRead = {}

messagingService:SubscribeAsync("Inbox", function(message)
  for _, n in pairs(message.Data) do 
    if n.ts > serverLaunchTime and not globalNotificationsRead[n.id] then 
      globalNotificationsRead[n.id] = true
      globalNotificationReceived(n)
    end 
  end
end)
How to send a message
messagingService:PublishAsync("Inbox", list) -- replace list here with what you want to send

How would I make those 2 you remade work in my game? The one I sent is just a portion of the global notification system I made since the Output only shows for that specific area

Anywhere you receive notifications, you should change to use SubscribeAsync. Anywhere you send notifications, you should change to use PublishAsync.

My rewrite wasn’t meant to be directly copy and pasted, but to be an example of how to change your code to use MessagingService.

Can you help me with my entire script though? It’s really important