Hey, I'm trying to make a script send a notification.
1 | function Notify(title,message,duration) |
2 | if title and message and duration then |
3 | game.StarterGui:SetCore( 'SendNotification' , { |
4 | Title = title; |
5 | Text = message; |
6 | Duration = duration |
7 | } ) |
8 | end |
9 | end |
So that wouldn't work inside a regular script. It has to be fired from a localscript. My case requires me to call it from a script and not a localscript. So far my best aim is to create a localscript with the content to send a notification. Either that or clone a script that already has it. I've tried the clone method that works only in studio but fails inside of the actual game.
You can use RemoteEvent for that, and make LocalScript use SendNotification when that event is fired.
01 | --LocalScript |
02 | local Event = <Path to RemoteEvent> |
03 |
04 | function Notify(title,message,duration) |
05 | if title and message and duration then |
06 | game:GetService( "StarterGui" ):SetCore( 'SendNotification' , { |
07 | Title = title; |
08 | Text = message; |
09 | Duration = duration |
10 | } ) |
11 | end |
12 | end |
13 |
14 | Event.OnClientEvent:Connect(Notify) |
I'm guessing you need to send notification to all players, and for that you can use RemoteEvent:FireAllClients(...)
method
1 | --Script |
2 | local Event = <Path to RemoteEvent> |
3 |
4 | function Notify(title,message,duration) |
5 | if title and message and duration then |
6 | Event:FireAllClients(title,message,duration) |
7 | end |
8 | end |