Use function from server.lua in client.lua

Good evening

I’m trying to call in a function from my server.lua file in my client.lua file.

I already tried RegisterServerEvent and TriggerServerEvent but this didn’t work out for me.

Files:
Client.lua

function triggerIntraAlert(alertID)
  TriggerServerEvent("addIntraAlert", alertID)

  SetNotificationTextEntry("STRING")
    AddTextComponentString(alertID)
    DrawNotification(true, true)
end

Server.lua

RegisterServerEvent("addIntraAlert")
AddEventHandler("addIntraAlert", function()

  MySQL.Async.fetchAll("INSERT INTO intraalerts (uid, alertid, message, active) VALUES(@name, @alertid, @message, @active)",
  {

  ["@name"] = "xPlayer.accounts[i].name",
  ["@alertid"] = "0",
  ["@message"] = "Vrij",
  ["@active"] = "1"
  
  }
)
end)

Thanks

Some of your code is incorrect, see here:

https://docs.fivem.net/scripting-manual/working-with-events/


This is in your trigger:

but not your handler:


This is incorrect.

Needs to be

RegisterNetEvent("eventName")

This is wrapping incorrectly

See here: