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

How to send a notification to all players via Gui?

Asked by 9 years ago

I want to make a script that will send a gui (notification) to everyone in the server. How do I do that?

0
At least give us a script to add on to. LateralLace 297 — 9y

1 answer

Log in to vote
19
Answered by 9 years ago
Edited 6 years ago

Remotes

I recommend using RemoteEvents for doing this. Whether it's the server notifying all players, or a player notifying all players, all GUI input should always be handled locally. I'll give an example of both scenarios from above.

Note

The local script will actually be doing all the work. The only thing we need the server to do is fire the remotes, which will fire the client-sided events.

Client sending notifications (Scenario one)

Let's say I have a local script inside a GUI button, and when I push the button, a GUI will appear on everyone's screen. First, let's see what this should look like on the server-side.

Server-side

local RepStorage = game:GetService("ReplicatedStorage")
local event = RepStorage:WaitForChild("Event")

event.OnServerEvent:Connect(function(client, request, ...)
    if request == "notify" then
        event:FireAllClients(request, ...)
    end
end)

Once OnServerEvent receives an update from the client, the server will then fire all other clients with the same information passed.

Client-side

event.OnClientEvent:Connect(function(request, ...)
    if request == "notify" then
        local gui = Instance.new("ScreenGui", playerGui)
        local textLabel = Instance.new("TextLabel", gui)
        textLabel.Text = ...
    end

end)

This is what each client will look like. Each client will have a listener that waits for the server to fire their event.

Server sending notifications (Scenario two)

This scenario involves the server sending the notifications to all players, instead of an individual client sending a notification to all players.

There's really no change here. We can simply just modify the code from the first server script, and should have something that looks like this:

Server-side

local RepStorage = game:GetService("ReplicatedStorage")
local event = RepStorage:WaitForChild("Event") 

event.OnServerEvent:Connect(function(client, request, ...)
    if request == "notify" then
        event:FireAllClients(Request, ...)
    end
end)

while wait(5) do
    event:FireAllClients("Notify", "Hello players.")
end

This may seem a bit complicated if you're not familiar with remotes, but I strongly recommend using them. Here's a tutorial on how to use remote events if you're interested.

Anyway, hope it helped. Let me know if you have any questions.

7
Your formatting is pleasing to me. User#6546 35 — 9y
5
dont get me wrong but i thought this was not a request site. i always got downvoted for asking a question like that Benqazx 108 — 8y
Ad

Answer this question