Client > Server event trigger not working?

on playerLoaded, im trying to send the player Identifier to the server script, but the function doesnt get called
(Please note that the msql code in there is just there to test if the function was being called, but it isnt)

Please tell me what im doing wrong as ive already read the documentation, im quite new to fivem development and lua in general, a few days, please point me in the right direction, the client/server scripts are in the picture, what am i doing wrong here? why is my server event not called by the client script on playerLoaded? (playerLoaded Works fine 100% sure)

First of all, idk why do u give server information that they already have… This can be easily exploited by cheaters. Also do u get some errors in console or F8?

Because im new to Fivem/lua, i dont know the PlayerLoaded server variant, i need to get the players wantedlvl from the db for blip color which is set in client script, if you know how to get the user identifier in the server script, please lmk, then i’d need to call the client function and pass the current wantedlevel to change the blip color, further, what do you mean by this can easily be exploited? its only the identifier right

1 Like

No errors btw otherwise id go off that

Try this:

-- Client
local connected = false

Citizen.CreateThread(function()
	AddEventHandler('playerSpawned', function()
		if not connected then
			TriggerServerEvent('GotNameEvent')
			connected = true
		end
	end)
end)
-- Server
ESX = exports['es_extended']:getSharedObject()

RegisterNetEvent('GotNameEvent')
AddEventHandler('GotNameEvent', function()
	local xPlayer = ESX.GetPlayerFromId(source)

	MySQL.update.await('UPDATE users SET wanted_level = ? WHERE identifier = ?', {5, xPlayer.identifier})
end)

About that exploiting, read this.

2 Likes

Appreciate you brother! Now i only need to create an event in the client that needs to be called from the server (so basically this the other way around) if you have the time for this, thanks alot, otherwise, thanks for the stuff above & have a good day!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.