When the player leaves the server, you cannot save or fetch their wanted level as it’s too late - they’ve disconnected.
The solution to your scenario is to store the player’s wanted level server-side by triggering a server event the moment they receive the wanted level. If the player’s wanted level increases/decreases then call your server to update itself again so your server is aware of the current wanted level for your player all the time. Then when the player disconnects, you can simply use the disconnected player’s ID as a reference to fetch their wanted level from the server to store on the database.
When player first receives a wanted level, we can send that information from a client script to the server
local wanted_level = 3 -- let's assume this means 3 stars
TriggerServerEvent("server_store_wanted_level", wanted_level) -- we send the info to the server
Then on the server we have the following
local wanted_levels = {} -- global variable on the server side to hold all wanted levels
RegisterNetEvent("server_store_wanted_level")
AddEventHandler("server_store_wanted_level", function(wanted_level)
local new_record = {} -- creating a new record
new_record.player = source -- assigning the player who received the wanted level to our new record
new_record.wanted_level = wanted_level -- storing the information we received from the client
table.insert(wanted_levels, new_record)
end)
Now when a player drops, all we have to do is match the player’s ID to the player IDs we have stored on the server (if it exists). If we find a match, we save it to database, otherwise we ignore and don’t do anything.
Just a friendly side note, there are many different ways to fetch, store and save data from a player, I have just given a basic example so you’re able to better understand the concept
i have this small script … it’s look like a blip , if any body enter the blib a get out he will get wanted level 5 stars
and also i add wanted level to database , then i upgrade the script with your example but it still working good but without saving the wanted level
thank you for your help and your time