[Help]How to connect money script to database to save the money?

local cashMoney = 0
local bankMoney = 0


RegisterCommand("addcash", function()
    cashMoney = cashMoney + 1
    MySQL.Async.execute("INSERT INTO police (`identifier`) VALUES ('"..identifier.."')", { ['@identifier'] = identifier}, "INSERT INTO moneyammount (`money`) VALUES ('"..cashMoney.."')", { ['@cashMoney'] = money})
    print("Cash Money: " .. cashMoney)
end)

RegisterCommand("addbank", function()
    bankMoney = bankMoney + 1
    print("Bank Money: " .. bankMoney)
end)

AddEventHandler("playerSpawned", function(spawn)
    print("Is this getting fired?")
    local time = 0
    local messagetime = 100000000000000000000000000000000000000000000000000000

    Citizen.CreateThread(function()
        while true do
        Citizen.Wait(0)
            while time ~= messagetime do
                Citizen.Wait(0)
                -- print("Cash Money: " .. cashMoney)
                -- print("Bank Money: " .. bankMoney)
                DrawText1("~b~Cash Money: ~g~$ " .. cashMoney)
                DrawText2("~b~Bank Money: ~g~$ " .. bankMoney)
            end
        end
    end)

    Citizen.CreateThread(function()
        while true do
        Citizen.Wait(0)
            while time ~= messagetime do
                Citizen.Trace(time)
                Citizen.Wait(1000)
                time = time +1
            end
        end
    end)
end)

function DrawText1(text)
    SetTextFont(0)
    SetTextProportional(1)
    SetTextScale(0.0, 0.50)
    SetTextDropshadow(1, 0, 0, 0, 255)
    SetTextEdge(1, 0, 0, 0, 255)
    SetTextDropShadow()
    SetTextOutline()
    SetTextEntry("STRING")
    AddTextComponentString(text)
    DrawText(0.10, 0.10)
end

function DrawText2(text)
    SetTextFont(0)
    SetTextProportional(1)
    SetTextScale(0.0, 0.50)
    SetTextDropshadow(1, 0, 0, 0, 255)
    SetTextEdge(1, 0, 0, 0, 255)
    SetTextDropShadow()
    SetTextOutline()
    SetTextEntry("STRING")
    AddTextComponentString(text)
    DrawText(0.425, 0.13)
end

Hi I am trying to connect my money system with a db but not sure how to exactly Can some one tell me what I am doing wrong?

you need to use multiple functions to draw text on the screen, also you need to call the draw text function on every game tick for it to be visible. Take a look here:

http://runtime.fivem.net/doc/reference.html#_0xCD015E5BB0D96A57
http://runtime.fivem.net/doc/reference.html#_0x25FBB336DF1804CB

Ok thanks Ill do that

Would this work now or?

local cashMoney = 0
local bankMoney = 0

RegisterCommand("addcash", function()
	cashMoney = +1

	print(cashMoney)
end)

RegisterCommand("addbank", function()
	bankMoney = +1

	print(bankMoney)
end)


AddEventHandler("playerSpawned", function(spawn)

   local time = 0
   local messagetime = 100000000000000000000000000000000000000000000000000000 
Citizen.CreateThread(function()
	while true do
	Citizen.Wait(0)
		while time < messagetime do
			Citizen.Trace(time)
			Citizen.Wait(1000)
 			time = time +1
		end
	end
end)

Citizen.CreateThread(function()
	while true do
	Citizen.Wait(0)
	local playerName = GetPlayerName( PlayerId() )
		while time < messagetime do
			Citizen.Wait(0)
			DrawText1("Cash "cashMoney)
			DrawText2("Bank "bankMoney)
		end
	end
end)

end)


function DrawText1(text)
	SetTextFont(0)
	SetTextProportional(1)
	SetTextScale(0.0, 0.50)
	SetTextDropshadow(1, 0, 0, 0, 255)
	SetTextEdge(1, 0, 0, 0, 255)
	SetTextDropShadow()
	SetTextOutline()
	SetTextEntry("STRING")
	AddTextComponentString(text)
	DrawText(0.10, 0.10)
end

function DrawText2(text)
	SetTextFont(0)
	SetTextProportional(1)
	SetTextScale(0.0, 0.50)
	SetTextDropshadow(1, 0, 0, 0, 255)
	SetTextEdge(1, 0, 0, 0, 255)
	SetTextDropShadow()
	SetTextOutline()
	SetTextEntry("STRING")
	AddTextComponentString(text)
	DrawText(0.425, 0.13)
end

Not sure, you’ll have to test it for yourself and see if it works.

Ok it should work as it is all there

It dont work but if you know why just let me know

to draw the text all you need is
You also dont need multiple drawtext functions. they can use the same function

Citizen.CreateThread(function()
		while true do
			Citizen.Wait(0)
			DrawText1("Cash ".. cashMoney)
			DrawText1("Bank ".. bankMoney)
        end
end)

@Vespura @Liam1
can u guys help me, I need help with the money system where i don’t receive any cash