Kazafka Posted January 4, 2020 Share Posted January 4, 2020 (edited) Attempt to do arithmetic on a nil value. And the code is: --Here you have the tables playersT = {"VaporZ"} moneyT = {"100"} addCommandHandler("deposit", function(player, commandName, amount) --Here is our "nil" value (I often use "100" for "amount", when I have $12,000) for k, v in ipairs(playersT) do if(string.match(playersT[k], getPlayerName(player))) then if amount and (tonumber(amount) <= getPlayerMoney(player)) then local i = table.find(players, getPlayerName(player)) local am = tonumber(amount) --Setting "am" as "amount", but changed into number takePlayerMoney(player, am) --Here's everyting ok moneyToLow = tonumber(moneyT[i]) - am --But here is a problem with "am" IDK why ("Attempt to do arithmetic on a nil value") moneyT[i] = tostring(moneyToLow) outputChatBox ("#09ff00Transfered into bank account #ffffff$" .. amount .. "#09ff00!", player, 255, 255, 255, true) end elseif(not string.match(playersT[k], getPlayerName(player))) then local size = table.size(playersT) local i = size + 1 playersT[i] = getPlayerName(player) moneyT[i] = amount takePlayerMoney(player, tonumber(amount)) outputChatBox ("#09ff00Transfered to bank account #ffffff$" .. amount .. "#09ff00!", player, 255, 255, 255, true) end end end) I will say only one thing - What The *F word here*?! Help! Edited January 4, 2020 by VaporZ Link to comment
Moderators IIYAMA Posted January 4, 2020 Moderators Share Posted January 4, 2020 (edited) 1 amount = tonumber(amount) if amount then -- loop here else -- inform the user that he has to fill in the amount end 2 local size = table.size(playersT) There is no table.size, only table.getn or #. The source of following error Attempt to do arithmetic on a nil value, that occurs on line 18: local i = size + 1 arithmetic = mathematics: + - / * local size = table.getn(playersT) local size = #playersT Edited January 4, 2020 by IIYAMA Link to comment
Kazafka Posted January 4, 2020 Author Share Posted January 4, 2020 6 minutes ago, IIYAMA said: 1 amount = tonumber(amount) if amount then -- loop here else -- inform the user that he has to fill in the amount end 2 local size = table.size(playersT) There is no table.size, only table.getn or #. The source of following error Attempt to do arithmetic on a nil value, that occurs on line 18: local i = size + 1 arithmetic = mathematics: + - / * local size = table.getn(playersT) local size = #playersT I'll try that tomorrow bro Link to comment
Kazafka Posted January 5, 2020 Author Share Posted January 5, 2020 11 hours ago, IIYAMA said: 1 amount = tonumber(amount) if amount then -- loop here else -- inform the user that he has to fill in the amount end 2 local size = table.size(playersT) There is no table.size, only table.getn or #. The source of following error Attempt to do arithmetic on a nil value, that occurs on line 18: local i = size + 1 arithmetic = mathematics: + - / * local size = table.getn(playersT) local size = #playersT Nah bro, I have a special function for table.size(theTable), but it says that it tries to preform arithmetic on a nil value on line 13, I don't know why bro. On line 12* 12 hours ago, IIYAMA said: 1 amount = tonumber(amount) if amount then -- loop here else -- inform the user that he has to fill in the amount end 2 local size = table.size(playersT) There is no table.size, only table.getn or #. The source of following error Attempt to do arithmetic on a nil value, that occurs on line 18: local i = size + 1 arithmetic = mathematics: + - / * local size = table.getn(playersT) local size = #playersT You know what's funny? That the table.find(table, "word") isn't working the whole time! But I tought that it will work, 'cause I have a special function for that! Anyways, I'm trying now to figure out to make depositing money to bank working Gimme time please 'K! Finally! It started working But the point is, that I need to test another way to deposit money to bank. This way depends on, if you don't have a bank account yet! 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