[Help] RegisterNetEvent/TriggerClientEvent Bugged?

Still working at my own custom map loader and have made a lot of progress today, however I’ve come to an utter and complete halt because I can’t get custom events to work for whatever reason. Just for a test, after I’ve finished parsing my .xml file (which I know is successful, because I use RconPrint and have made sure the tables are populated correctly) I run this;

TriggerClientEvent("SS-Race:TransferMapData", -1)

Then in the client-sided script, it looks like this;

function OnReceiveMapData_Handler()
	TriggerEvent("chatMessage", "[SS-Race]", {0, 187, 0}, "Haaay")
AddEventHandler("SS-Race:TransferMapData", OnReceiveMapData_Handler)

This absolutely refuses to execute and I have no idea why. I’ve tried clearing the cache. I’ve tried renaming it so many times I’ve lost count. I’ve tried switching place of the client and server scripts in the __resource file. Nothing.

At the mo-mo my __resource looks like this;

resource_type "gametype" { name = "SS-Race" }

dependencies {

client_script "MapLoader_Client.lua"
server_script "MapLoader_Server.lua"

Any assistance with this would be greatly appreciated…

You forgot who to send the message to.

TriggerClientEvent("chatMessage", -1, "[SS-Race]", {0, 187, 0}, "haaay!")

That’s in the client-sided script though, surely I don’t have to provide a NetID and can just use TriggerEvent? Sorry for not clarifying that :slight_smile:

1 Like

ah I see, sorry for misunderstanding.
you should be able to use TriggerEvent("chatMessage",..., yes
Did you try making the function inline? Also, there were issues with dashes with events in the past, so try without dashes as well. Make sure to actually check F8 console to see if the event is even being triggered at all as well.

I doubt it’s that, I had it called onReceiveMapData before, but reckon maybe it was conflicting with something. Thus I renamed it to SS-Race:TransferMapData. I’ll try some other names and see if it makes any difference.

There’s nothing out of the ordinary in the F8 console, if I recall correctly it said the event was queued. Will have to confirm that later.

Well then just try making it an inline handler, that’s what might be breaking, you never know.

AddEventHandler("SS-Race:TransferMapData", function()
    TriggerEvent("chatMessage", "[SS-Race]", {0, 187, 0}, "Haaay")

Sorry for the late response, just tried that along with some other random event names. Neither works. Also something peculiar is that when I first start the resource after having closed the server and cleared the cache - it seems my function is triggered several times. I call it via the onResourceStart event.

When I restart it afterwards it only runs once (yeah I know I forgot to reset the line counter).

Edit: Also tried renaming the client-side script and still no bueno. I’ve no idea what’s going on :smile:

Edit2: Just made sure the script is loaded by making it output a message. So definitely something with the events going on here.

El Edito3: Think I found it, the issue stems from me trying to use onResourceStart. Seems that is fired before the client-sided script has a chance to load. Thus it never managed to trigger the event.

Instead I use onClientResourceEvent to trigger a server-event… to trigger a client-event… This seems kind of wrong, especially since the client-sided script is put first in the __resource file…?

onResourceStart event is called for every single started up resource - check if it’s your resource, and only then do stuff.

AddEventHandler('onResourceStarted', function(resource)
    if resource == "SS-Race"  then
        -- do stuff

Yeah I figured as much, I already have that if statement in place. If I stop the server, clear the cache, fire it back up and start the resource - that event is triggered more than once.