Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

The proper way to SendNotification through a NON Localscript?

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.

1 comment

0

Is there a reason you don't want to use local scripts?

1 answer

✓ Accepted answer

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

3 comments

0

Is it possible to send to one client? Particularity one that just joined? I.e a welcome message?

0

There's "FireAllClients" and then there's "FireClient(playerName)" so yes.

0

Perfect, absolutely perfect. My god I love this site.

This discussion is preserved as it was. New answers, comments, and votes are closed.