HireAmine Posted September 1, 2022 Share Posted September 1, 2022 How i can save player money and location when the player leave the server i tried a code before but it didnt work. it says on line 9 getPlayerMoney(expected player element) PLEASE HEEEELP this error takes me 5 days --local connection = exports.db:getConnection() local account = "" local player = "" function writedata(query) local connection = exports.db:getConnection()--I have another script that exports the connection local result = dbPoll(query, 0) if (#result > 0 ) then local up = dbQuery(connection, "UPDATE players SET money = ? WHERE account = ? ", getPlayerMoney(player), account)--Update player money if found result dbFree(up) elseif (#result == 0 ) then local insert = dbQuery(connection, "INSERT INTO players (account, money) VALUES(?, ?) ", account, getPlayerMoney(player))--insert player money if found result end end --addEventHandler("onPlayerLogout", root, function(acc) --local connection = exports.db:getConnection()--I have another script that exports the connection --player = source--reset the player element variables --account = acc --d--bQuery(writedata, connection, "SELECT * FROM players ", source, accout) --end) function quit() local connection = exports.db:getConnection()--I have another script that exports the connection player = source--reset the player element variables account = getPlayerAccount(source) dbQuery(writedata, connection, "SELECT * FROM players ", source, accout) setElementData(source, "d", 45) end addEventHandler("onPlayerQuit", root, quit) function returnn(select) local connection = exports.db:getConnection()--I have another script that exports the connection local result = dbPoll(select, 0) for i, v in pairs(result) do if v.money then--check if there is a value setPlayerMoney(player, v.money)--set the player money end end end addEventHandler("onPlayerLogin", root, function(_, acc) local connection = exports.db:getConnection()--I have another script that exports the connection account = acc--reset the account variable player = source--reset the player element variable local select = dbQuery(returnn, connection, "SELECT * FROM players") end) Link to comment
Sendy Posted September 2, 2022 Share Posted September 2, 2022 (edited) function writedata(query) local connection = exports.db:getConnection()--I have another script that exports the connection local result = dbPoll(query, 0) if (#result > 0 ) then local up = dbQuery(connection, "UPDATE players SET money = ? WHERE account = ? ", getPlayerMoney(source), account)--Update player money if found result dbFree(up) elseif (#result == 0 ) then local insert = dbQuery(connection, "INSERT INTO players (account, money) VALUES(?, ?) ", account, getPlayerMoney(source))--insert player money if found result end end Edited September 2, 2022 by Sendy Link to comment
HireAmine Posted September 6, 2022 Author Share Posted September 6, 2022 it didnt work still the sam error if you can please make a script that save my money and position with mysql and i will try to understand it please Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now