C# ServerSide TriggerEvent To Lua?

I’m trying to trigger an event from my C# script which needs to interface with a LUA written source. All my inner-C#-events seem to go just fine.

When I use something like

        private async void _buildCharacter([FromSource]Player srcPlayer, string firstName, string lastName, int charAge)
        {
            
            srcPlayer.TriggerEvent("myEvent");

Which leads out to a LUA controlled event, nothing happens. If I just use, TriggerEvent("myEvent"); the event will fire, but I’m thinking this is making the event fire for everyone as no player is specified?

on the LUA side of things the event is registered.

RegisterServerEvent("myEvent")
AddEventHandler("myEvent", function()

Any help would be appreciated, I’m just kinda spinning my wheels D=

If I understand correctly, the C# part of your script is server-side, right? Are you trying to trigger Lua on the server, or the player?

If the server, you just need to use the TriggerEvent(...) alone. If you want to trigger a client event, you could either do TriggerClientEvent(playerObject, name, args...) or like the way you have done.

1 Like

Both are serverside scripts, so if I use TriggerEvent() it will execute the server event with our player as source ? I just wanna make sure if I’m using TriggerEvent() it’s not going to fire the event off serverside for everyone.

I’m just a little confused on TriggerEvent() vs player.TriggerEvent()

TriggerEvent() will trigger another event on the server (or if it is run on a client, it will trigger another event on that client). If you trigger the event on the server, it will call the server event with the server as a source. You could pass the player object as a parameter, but it will not be the source unless it is directly triggered from the event handler.

The player.TriggerEvent() is the same exact thing as calling TriggerClientEvent() and having it go to that one player.

2 Likes

Thank you so much, got myself a bit confused for a second there, but I got it now =)