Jump to content

getAccountData problem


SkatCh

Recommended Posts

guys please i need some help how can i fix this i create a medkits system but i have a problem when i try to save player medkits .

function getPlayerMedKits(player) 
    local medKits = tonumber(getAccountData(player, "medKits")) or 0 
    return medKits 
end 
  
function setPlayerMedKits(player, amount) 
    setAccountData(player, "medKits", tostring(amount)) 
    getPlayerAccount(player, "medKits", tostring(amount)) 
    triggerClientEvent(player, "onMedKitLoad", player, amount) 
    return true 
end 

warnings :

-Bad argument @ 'getAccountData' [Expected account at argument 1, got player ]

-Bad argument @ 'setAccountData' [Expected account at argument 1, got player ]

Link to comment
local medKits = tonumber(getAccountData(getPlayerAccount(player), "medKits")) or 0 

EDIT: May I ask why you are getting the account with 'getPlayerAccount' in the second function without doing anything with it? Or is it an other function in the script?

Link to comment

Try, it will be works perfectly:

function getPlayerMedKits(player) 
    local account = getPlayerAccount(player) 
    if not account then outputChatBox("Player not logged in!") return 0 end 
    local medKits = getAccountData(account, "medKits") or 0 
    return medKits 
end 
  
function setPlayerMedKits(player, amount) 
    local account = getPlayerAccount(player) 
    if not account then outputChatBox("Player not logged in!") return false end 
    setAccountData(account, "medKits", tonumber(amount)) 
    --WTF? getPlayerAccount(player, "medKits", tonumber(amount)) 
    triggerClientEvent(player, "onMedKitLoad", player, tonumber(amount)) 
    return true 
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...