Yes it wouldn’t work, but you would see the event <eventname> was not safe for net
message, that is if you are triggering a server event from the client or a client event from the server.
If you are triggering a server event from a server script (or client event from a client script) you don’t need to register the event (you can, but it works fine if you do it without registering).
For example:
server_script_one.lua
AddEventHandler('test', function()
print("success")
end)
server_script_two.lua (note this is delayed to make sure the other script is loaded before executing the event)
Citizen.CreateThread(function()
Citizen.Wait(100)
TriggerEvent('test')
end)
Server console output:
success
However if you try to trigger the ‘test’ event from a client script, like so:
TriggerServerEvent('test')
You get this error in the client console.
event test was not safe for net
This is because the event isn’t registered to be used cross client/server.
To fix this, simply add RegisterServerEvent("test")
to your server script like so:
RegisterServerEvent("test")
AddEventHandler('test', function()
print("success")
end)
now the output will be this in your server console
success
success
(remember, it prints “success” twice because the server_script_two.lua triggers it once, then the client also triggers it.)
The example above just covers the server to server and client to server scenario, but it is the same for client to client and server to client scenarios.
This is also the same if you want to do it cross resource. example:
resource_one_server_script.lua
TriggerEvent('test")
resource_two_server_script.lua
AddEventHandler('test', function()
print("success")
end)
Output in server console: success