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.
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