Send Screen.ShowNotification to all players (C#)

Hi there FiveM!

I am currently making a panic button script. Everything works so far, but I can’t figure out how to show a notification to all players from the Server side. I know that one the Client side, we can utilize Screen.ShowNotification(x), but I can’t find out how to do the same on the server side.

Can somebody please offer a solution? Thanks so much!

Hello RoyaltyModifications,

create on clientside an event and trigger this on serverside:

-- This is how you trigger a clientside event from serverside
TriggerClientEvent('EVENT', source, param1, param2...)

Use the source -1 to trigger this event for each player.

Regards :ok_hand:t2:

Hi, is this meant for C#? When I put it into my Server.cs file, it displays an error.

Sorry, I don’t know C#, but I’m sure it’s the same logic, just another syntax. See the docs for this.

What @Tuncion is talking about this.

Client:

[EventHandler("TestScript:Client:sendMessage")]
private void SendMessage(string message) => Screen.ShowNotification(message);

Server:

private void TestScriptMethod() => TriggerClientEvent("TestScript:Client:sendMessage", "test");

TriggerClientEvent gives me an error on both client and server sides. It underlines in red as if it’s not a function. Am I missing a project reference?

TriggerClientEvent of course will give you an error on the Client side. It wasn’t made for the Client side, it’s ment for the server side. What does your code look like?

You probably don’t have this added to your class.

image

I have it on both the server and client.


image

:thinking:

at this point my suggestion is to reinstall the FiveM library as it seems like it’s corrupted. BaseScript is where the TriggerClientEvent comes from. When I make my scripts I usually use the cook book for quick install.

Sorry, would you mind sending me a link to where I can re-download the library?

https://cookbook.fivem.net/
https://www.nuget.org/packages/CitizenFX.Core.Server
https://www.nuget.org/packages/CitizenFX.Core.Client

That fixed it. Thank you so so much!

I’ve been trying to do this for at least a week now, you’ve been an amazing help!