Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

The proper way to SendNotification through a NON Localscript?

Asked by 6 years ago

Hey, I'm trying to make a script send a notification.

function Notify(title,message,duration)
    if title and message and duration then
        game.StarterGui:SetCore('SendNotification', {
            Title = title;
            Text = message;
            Duration = duration
        })
    end
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.

0
Is there a reason you don't want to use local scripts? Vulkarin 581 — 6y

1 answer

Log in to vote
1
Answered by
Mokiros 135
6 years ago

You can use RemoteEvent for that, and make LocalScript use SendNotification when that event is fired.

--LocalScript
local Event = <Path to RemoteEvent>

function Notify(title,message,duration)
    if title and message and duration then
        game:GetService("StarterGui"):SetCore('SendNotification', {
            Title = title;
            Text = message;
            Duration = duration
        })
    end
end

Event.OnClientEvent:Connect(Notify)

I'm guessing you need to send notification to all players, and for that you can use RemoteEvent:FireAllClients(...) method

--Script
local Event = <Path to RemoteEvent>

function Notify(title,message,duration)
    if title and message and duration then
        Event:FireAllClients(title,message,duration)
    end
end
0
Is it possible to send to one client? Particularity one that just joined? I.e a welcome message? LucarioZombie 291 — 6y
0
There's "FireAllClients" and then there's "FireClient(playerName)" so yes. MythicalShade 420 — 6y
0
Perfect, absolutely perfect. My god I love this site. LucarioZombie 291 — 6y
Ad

Answer this question