[Request][Help] Player disconnects need script to save money

Hello, using essentialsmode(mysql) and es_freeroam1.3? so i can use police job.

But having and issue whenever i disconnect it sets my money (on Hand) in db to 0. No matter if +100 or -3000 it goes to 0.

So looking for a script that would save when a player disconnects.

Thanks allot of any help.

essentialmode/server/main.lua

AddEventHandler(‘playerDropped’, function()
if(Users[source])then
TriggerEvent(“es:playerDropped”, Users[source])

  db.updateUser(Users[source].identifier, {money = Users[source].money, Users[source].bank}, function()
  	Users[source] = nil
  end)

end
end)

By default it’s supposed to be there.

Thanks allot, it was changed. not sure if old version or what but it wasn’t what you posted. Been trying to figure out the cause for hours apon hours now.

i narrowed down to line 54, but wasn’t sure what to do to fix it, so thanks allot.

Thats for mysql right? just to confirm.

just checked new version, and it same :frowning:

need fix for mysql not sure what going on.

is in mysql version.

AddEventHandler('playerDropped', function()
	if(Users[source])then
		TriggerEvent("es:playerDropped", Users[source])

		MySQL:executeQuery("UPDATE users SET `money`='@value' WHERE identifier = '@identifier'",
		{['@value'] = 0, ['@identifier'] = Users[source].identifier})

		Users[source] = nil
	end
end)

is

{['@value'] = 0

setting db to 0?

My files for MySQL version with bonus to put any car in garage when player disconnect.

AddEventHandler(‘playerDropped’, function()
if(Users[source])then
TriggerEvent(“es:playerDropped”, Users[source])

MySQL:executeQuery("UPDATE users SET `money`='@value' WHERE identifier = '@identifier'",
{['@value'] = Users[source].money, ['@identifier'] = Users[source].identifier})

MySQL:executeQuery("UPDATE user_vehicle SET vehicle_state='Rentré' WHERE identifier = '@identifier'",
{['@identifier'] = Users[source].identifier})
Users[source] = nil

end
end)

1 Like

Thanks much, i’m literally just testing out

MySQL:executeQuery("UPDATE users SET `money`='@value' WHERE identifier = '@identifier'",
		{['@value'] = Users[source].money, ['@identifier'] = Users[source].identifier})

		Users[source] = nil

that i found,

and it worked, thanks allot.

hi, i follow your code but it seem to not working. Where do i place the code exactly? do i need to require mysql inorder for this code to work? I am trying to spawn back the car after user disconnected. Thank you!

Have you fixed it ? Can you tell me how ?

hello guys i have same problem,
money and bank cant be saved, dont get error
 just don save

i try put that codes on place but when i do that is like script dosent work anymore dont show bank and money :\

any ideia ?