Hi,
I’m creating my script but I have a problem. So here is my code:
function LoadUser(steamid, source)
MySQL.Async.fetchAll("SELECT * FROM users WHERE steamid = @steamid LIMIT 1", {['@steamid'] = steamid}, function(result)
if result[1] ~= nil then
--local user = {id = source, steamid = steamid, name = result[1].name, level = result[1].level, money = result[1].result, dirty = result[1].dirty, bank = result[1].bank, number = result[1].number, job = result[1].job}
--Users[steamid] = user
print(steamid)
Users[steamid].identifier = steamid -- Line 61
Users[steamid].name = result[1].name
Users[steamid].level = result[1].level
Users[steamid].money = result[1].money
Users[steamid].dirty = result[1].dirty
Users[steamid].bank = result[1].bank
Users[steamid].number = result[1].number
Users[steamid].job = result[1].job
print("Money: "..Users[steamid].money)
TriggerClientEvent('erp:showMoney', Users[steamid].money, Users[steamid].dirty, Users[steamid].bank)
TriggerEvent('erp:playerSpawned', Users[steamid])
else
RegisterUser(steamid, source)
end
end)
end
And the error:
I don’t know why it does not work. If a person can help me. Thank you
I think it’s because you’re trying to get the result in the database of a name that does not exist or is badly written.
print('1')
print(result[1].name)
print('2')
print(result[1].level)
print('3')
print(result[1].dirty)
print('4')
print(result[1].bank)
print('5')
print(result[1].number)
print('6')
print(result[1].job)
Try to see what this gives before :
Users[steamid].identifier = steamid -- Line 61
Users[steamid].name = result[1].name
Users[steamid].level = result[1].level
Users[steamid].money = result[1].money
Users[steamid].dirty = result[1].dirty
Users[steamid].bank = result[1].bank
Users[steamid].number = result[1].number
Users[steamid].job = result[1].job
But the line is
Users[steamid].identifier = steamid -- Line 61
nothing with result
Oops I did not have time to edit … look at my edit. ^^
Try this …
Users = {}
function LoadUser(steamid, source)
MySQL.Async.fetchAll("SELECT * FROM users WHERE steamid = @steamid LIMIT 1", {['@steamid'] = steamid}, function(result)
if result[1] ~= nil then
id = tostring(steamid)
Users[id] = {
identifier = id,
name = result[1].name,
level = result[1].level,
money = result[1].money,
dirty = result[1].dirty,
bank = result[1].bank,
number = result[1].number,
job = result[1].job
}
print("Money: "..Users[id].money)
TriggerClientEvent('erp:showMoney', Users[id].money, Users[id].dirty, Users[id].bank)
TriggerEvent('erp:playerSpawned', Users[id])
return Users[id]
else
RegisterUser(steamid, source)
end
end)
end
No error, it should be good thank you
1 Like
For the solution I think this is because you did not initialize the Users array. 
No Users is initialize at the top of file
So it’s either the steamid that was in int, or the fact that you were trying to add indexes to the table with Users [steamid] .myIndex. To know it would have to try to do the same thing with table.insert but good if it works one gets crazy!
Probably steamid is an int wtf fx
1 Like