Attempt to index nil with 'ShowNotification'

Roblox has recently added a new service known as “ToastNotificationService”, and I wanted to see if I can get this working.

There are 2 known functions of ToastNotificationService:

One of the arguments for ShowNotification is “messageId” which is supposed to be a string. The problem is that I have no clear indication on what I am supposed to enter here. What is the messageId supposed to be? A number, a GUID?

I’m 100% sure that my script to grab the service is correct, and the script is this:

game:FindFirstChildOfClass("ToastNotificationService")

(it’s really annoying to find the service because :GetService() fails to work)

If I could get an answer to this, it would be appreciated.

(Also yes, I know that this is a CoreScript only service, but I want to try and get this working to see what this is used for.)

1 Like

i believe FindFirstChild and FindFirstChildOfClass returns bool
so yeah i still use game:GetService(‘service name’) or game[‘service name’]

The problem with this is that trying to use :GetService or game.Service will just error with the following error:

ToastNotificationService is not a valid Service name

or

ToastNotificationService is not a valid member of DataModel "Game"

I’m not really sure what to do in this case. The service appears within Studio, but not in games?

None of the functions are usable and the service is probably inaccessible; limited to CoreScripts.

Maybe try this? Don’t know if it’ll work.

game.ToastNotificationService

According to the documentation it says that it is limited to CoreScripts. However the thing is that I am running scripts under a high level context (CoreScript level) and it does not appear to work in live places. However, I am able to use GetService on ToastNotificationService in Studio, the problem being that I am unable to Class security check in Studio.

Somehow, I’d need to find out how to run at CoreScript level in Studio. The service does not appear at all in game, but does appear in Studio. Weird.

Strange, on the API it says that it can be retrieved using game:GetService().

It can be retrieved with GetService() in Studio (i.e the Command Bar), but not in actual live running games.

1 Like

this should work, waiting until the game loads perfectly

function getService(name)
  repeat wait() until game:FindFirstChild(name)
  return game:WaitForChild(name)
end

This is not true. :FindFirstChild(), :FindFirstChildWhichIsA() or :FindFirstChildOfClass() loop through all children of the given Instance. It will return the first child with the given name or the first child of the given class. If there isn’t a child with this name or of this class, it will return nil. The reason you can use

if Instance:FindFirstChild("String") then
    --There is a child called "String".--
end

is because it also runs code inside the if statement if the value isn’t false or nil.

i dont use findfirstchild too much so sorry /shrug

1 Like

I wrote some messy code to try and locate the service within game. That code being:

function findtheservice()
  repeat wait() until game:FindFirstChildOfClass("ToastNotificationService")
  return game:WaitForChild("ToastNotificationService")
  end
  if not game:FindFirstChild("ToastNotificationService") then
      print("Failed to locate service") elseif game:FindFirstChild("ToastNotificationService") then print("Located service")
end

The game then proceeded to print “Failed to locate service”.

Therefore, the service is irretrievable in live games, but is retrievable in Studio, for some reason. I’ll need to find a way to run at CoreScript context in Studio to get this working.

dont forget to put an ‘end’ after if and then

I don’t know why I need to even say this. If it’s made for CoreScripts only then it means only CoreScripts can access it. Roblox blocks access to these for a reason.

1 Like

It seems like using this service basically isn’t possible. On the Developer Hub it says it can only be used for CoreScripts. This means only Roblox can use it.