Jump to content

[Help]Saving player's money and on scoreboard


GamingTim

Recommended Posts

I'm learning slowly but i'm trying to make this simple script to work, it didn't work but only showed me the "money" tab on the scoreboard but I don't get the player's money when they join also I wanted to save the player's money when they quit. here's the code and idk how to fix it.

exports.scoreboard:addScoreboardColumn('Money') 
  
  
function GetPlayerMoney(player) 
    local account = getPlayerAccount(player) 
    if isGuestAccount(account) then return end 
    local GetPlayermoney = getAccountData(account,"GetPlayerMoney") 
    if not GetPlayerMoney then setAccountData(account,"GetPlayerMoney",0) end 
    end 
  
  
addEventHandler("onPlayerLogin",root, 
function () 
    local account = getPlayerAccount(source) 
    if isGuestAccount(account) then return end 
    local GetPlayerMoney = getAccountData(account,"GetPlayerMoney") 
    if GetPlayerMoney then 
        setElementData(source,"GetPlayerMoney",tostring(player)) 
    else 
        setElementData(source,"GetPlayerMoney",0)     
  
end 
end) 

Link to comment

Try this ..

  
Server Side # 
  
function Quit() 
    local playeraccount = getPlayerAccount ( source ) 
    if not playeraccount or isGuestAccount(playeraccount) then return end 
    setAccountData ( playeraccount, "Money", getPlayerMoney ( source ) )  
end 
addEventHandler("onPlayerQuit",root,Quit) 
  
function join(_,playerAccount)     
    local playerMoney = getAccountData(playerAccount, "Money")      
    setPlayerMoney ( source , playerMoney ) 
end 
addEventHandler( "onPlayerLogin", getRootElement(), join) 

I think the money automatically changes in the scorebord

Link to comment
exports.scoreboard:addScoreboardColumn('Money') 
  
function GetPlayerMoney(player) 
    local account = getPlayerAccount(player) 
    if isGuestAccount(account) then return end 
    local GetPlayermoney = getAccountData(account,"GetPlayerMoney") 
    if not player then setAccountData(account,"GetPlayerMoney",0) end 
  
  
addEventHandler("onPlayerLogin",root, 
function () 
    local account = getPlayerAccount(source) 
    if isGuestAccount(account) then return end 
    local GetPlayerMoney = getAccountData(account,"GetPlayerMoney") 
    if GetPlayerMoney then 
        setElementData(source,"GetPlayerMoney",tostring(player)) 
    else 
        setElementData(source,"GetPlayerMoney",0)     
  
end 
end) 
  

Link to comment

Well, obviously you didn't look for errors, since I found one the moment I seen the script, plus, the debugscript also shows it.

function GetPlayerMoney(player) 
    local account = getPlayerAccount(player) 
    if isGuestAccount(account) then return end 
    local GetPlayermoney = getAccountData(account,"GetPlayerMoney") 
    if not player then setAccountData(account,"GetPlayerMoney",0) end 

In that function, you got an 'end' missing.

Link to comment

What are you doing?

if not player? wtf

if the player does not exists then how the account will be exists?

if not player then setAccountData(account,"GetPlayerMoney",0) end 

tostring(player)? is player even defined anywhere?

setElementData(source,"GetPlayerMoney",tostring(player)) 

And then back to function GetPlayerMoney you're not using the function anywhere, you just used a variable called 'GetPlayerMoney'. Also you never set a data to the key 'Money'.

And you never saved anything when the player quit from the server.

This make no sense.

Link to comment

I edited and added the stuff needed, does this still makes sense?|

V

exports.scoreboard:addScoreboardColumn('Money') 
  
addEventHandler("onPlayerQuit",root,  
function GetPlayerMoney(player) 
    local account = getPlayerAccount(player) 
    if isGuestAccount(account) then return end 
    local getPlayermoney = getAccountData(account,"getPlayerMoney") 
    if not player then setAccountData(account,"getPlayerMoney",0) end 
    end 
  
  
addEventHandler("onPlayerLogin",root, 
function () 
    local account = getPlayerAccount(source) 
    if isGuestAccount(account) then return end 
    local getPlayerMoney = getAccountData(account,"getPlayerMoney") 
    if getPlayerMoney then 
        setElementData(source,"setPlayerMoney",tostring(player)) 
    else 
        setElementData(source,"setPlayerMoney",0)     
  
end 
end) 

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...