SetPlayerWantedLevel randomly broke

Client

Using canary? No
Windows version: 8.1
System specifications: A10 6800K, 16GB RAM, GTX 1060

Server

Operating system: Windows Server 2016
Artifact version: 1623
IP address: Private
Resources: 100+
System specifications: Intel Core I7, 5GB RAM

Incident

Summary: Native SetPlayerWantedLevel randomly broke when running on OneSync.
Expected behavior: To run normally
Actual behavior: Is causing a error on F8
Steps to reproduce: At this moment, its completely random.
Server/Client? Client
Files for repro (if any):
Error screenshot (if any):


.dmp files/report IDs:

Any additional info:
Never happen on Non-OneSync, only on OneSync.
Happened with 3 players on the server, but players has already reported this when the server is full with 32 players.
I tested on a different script using the SetPlayerWantedLevel native with NULL playerId and playerId = 0, but none has the same result from the error.
Code used on my script (inside a while with Citizen.Wait(0)):

local playerId = PlayerId()
if GetPlayerWantedLevel(playerId) ~= 0 then
	SetPlayerWantedLevel(playerId, 0, false) -- Line 801
	SetPlayerWantedLevelNow(playerId, false)
end
1 Like

Hmm, maybe try doing like idk setting wanted level to 1 or something? :stuck_out_tongue:

1 Like

It seems like that the source is not defined/clear try to put this in your code:

 if (source == nil) then
     print("player not found, source is not defined")
end

If the message “player not found” appears then you know that the source is not defined.

Little help: source problems come often when you trigger a client event from the server without sending the source in it.

But this code is client-side dude.

Seems the (technically unneeded) netGameEvent list is overflowing. How frequently are you calling this native in a row?

Only that script use this native. This is the full code:

Citizen.CreateThread(function()
	while true do
		if not playerIsOnRestrictArea and not hasCopsChaseOn then
			local playerId = PlayerId()
			if GetPlayerWantedLevel(playerId) ~= 0 then
				SetPlayerWantedLevel(playerId, 0, false) --Line 801
				SetPlayerWantedLevelNow(playerId, false)
			end
			
			Citizen.Wait(0)
		else
			Citizen.Wait(500)
		end
	end
end)

Hi, this is already happend to me with some other natives. This was caused by disconnection and reconnection to the server.When disconnected this errors was printed and not after the reconnection. You can maybe make some ping tests when it happend just to be sure ?

Well, i play using netgraph, and nothing was strange when this happened. The only strange thing was my game freezing for a second when the error has been printed on F8.

I’ve only see this error when i was using bad resource manifest and more recently with fast and silent deconnection/reconnection.In my case the problem come from my bad network (maybe not your case) . But don’t waste your time to try other ways to execute your code the problem is surely somewhere else i guess.

Well, i’m using the most recent manifest on that resource, and my server network is running good (This native broke has happened with only 3 players on server, but already was broke with a lot more). I will wait for more informations from FiveM Elements. But thanks for the help dude.

Ok, good luck dude. :+1:

1 Like

I am getting script error from this same native on OneSync aswell.
It seems to work for a while until people get resource warning and then a script error. Then have to reconnect to the server and then it works fine again. I have no idea what might be causing this.


Code:

Citizen.CreateThread(function()
	while true do
		Citizen.Wait(1)
		for i = 1, 12 do
			EnableDispatchService(i, false)
		end
		SetPlayerWantedLevel(PlayerPedId(), 0, false)  -- Broken?
		SetPlayerWantedLevelNow(PlayerPedId(), false)
		SetPlayerWantedLevelNoDrop(PlayerPedId(), 0, false)
	end
end)