attempt to perform arithmetic

Hi,
I have a big problem, I develop a bank system, so I need a button to transfer money from the inventory to the bank, but I have this error.

attempt to perform arithmetic “monaywanttransfered” <a nill value>

Client-Side:

local transfertenum = vgui.Create(“DNumberWang”, f)
transfertenum:SetDecimals(0)
transfertenum:SetKeyboardInputEnabled(true)
transfertenum:SetSize(210,30)
transfertenum:Center()

local transferenum_button = vgui.Create( "DButton", f)
transferenum_button:SetPos( 335, 190 )
transferenum_button:SetSize( 90, 15 )
transferenum_button:SetText("")

local transfer_name = vgui.Create("DLabel", transferenum_button)
transfer_name:SetPos(5,2)
transfer_name:SetSize(70, 10)
transfer_name:SetFont("default")
transfer_name:SetText("VALIDATE")
transfer_name:SetTextColor( Color(250, 250, 250, 255) )

transferenum_button.DoClick = function()
   net.Start("Transfer_To_Bank")
    moneywanttransfered = transfertenum:GetValue()
	net.WriteString(tostring( moneywanttransfered))
   net.SendToServer()
end

transferenum_button.Paint = function()
	SKINS:DrawFrame(transferenum_button:GetWide(), transferenum_button:GetTall())
end

Server-Side

net.Receive(“Transfer_To_Bank”, function(len, ply)
local name = net.ReadString()
local item = getItems( name )
local currentmoneybank = ply:databaseGetValue( “moneybank” )
local currentmoney = ply:databaseGetValue( “money” )

ply:databaseSetValue( "money", currentmoney + moneywanttransfered )
ply:databaseSetValue( "moneybank", currentmoneybank - moneywanttransfered )
ply:PrintMessage( HUD_PRINTTALK, "[BANK] You have transfered: "..moneywanttransfered.." RU , in your inventory." )

end)

Please help me I try a lot of things, nothing works

Your Transfer_To_Bank net message writing doesn’t make sense. You’re writing “moneywanttransfered”, but you’re reading it as “name” serverside then still accessing “moneywanttransfered” without declaring it.

Why are you sending a string instead of a double or integer? What you’re doing is very inefficient.

code_gs:

Thank you for your comment,
I should not use “string” then?

LegoGuy:

Thanks you,

I just want to get back the amount that the players type and send it to the server-side, I only learned this way

Send and read it as a number

Yes I thank you, but I can not find the right “net.” i try a lot of net. wiki…

Try net.Read/WriteDouble

You should also be checking if they have enough money in their bank before you change any values server side. Anyone who bypasses sv_allowcslua can run that net message and give them self any amount of money even if they don’t have enough stored in their bank.

Unless you’re checking it inside the ply:databaseSetValue function

Actually I know that players can exploit, but first I wanted to solve the problem of the net. Thank you even for your comment, and I will try the “WriteDouble” said above.

EDIT: WriteDouble = same error…

Because you’re not reading it properly!

Sorry I still learn, if it was possible to have a very basic example you would be great…

Dude, it’s very simple

In your server-side code, you have this line:
[lua]
ply:databaseSetValue( “money”, currentmoney + moneywanttransfered )[/lua]

Yet you never defined moneywanttransfered. What is *moneywanttransfered *?

*“moneywanttransfered = transfertenum:GetValue()” *define after my “net.Start(“Transfer_To_Bank”)”

//

I would just like to know how to recover the encrypted value in “DNumberWang” and apply it to the player’s data, please…
I have been searching for days…

//

You do that on the client, not on the server

Thanks you very much i try again

Your messages did not make much progress but for the future developer I will note the solution!

CLIENT SIDE

transferenum_button.DoClick = function() // button
local datatowrite = {} // table
datatowrite.moneywanttransfered = transfertenum:GetValue() //table
net.Start(“Transfer_To_Bank”) // server-side
net.WriteTable(datatowrite) ** // stock table**
net.SendToServer() // send
end

SERVER SIDE

util.AddNetworkString( “Transfer_To_Bank”)** // comunication client to server**

net.Receive(“Transfer_To_Bank”, function(len, ply)
local datatowrite = net.ReadTable()
local name = net.ReadString()
local item = getItems( name )
local currentmoneybank = ply:databaseGetValue( “moneybank” )
local currentmoney = ply:databaseGetValue( “money” )
local minimumtransfer = 100
ply:databaseSetValue( “money”, currentmoney + datatowrite.moneywanttransfered ) // use table
ply:databaseSetValue( “moneybank”, currentmoneybank - datatowrite.moneywanttransfered ) // use table
ply:PrintMessage( HUD_PRINTTALK, “[BANK] You have transfered: “…datatowrite.moneywanttransfered…” RU , in your inventory.” )
end)

You wrote “moneywanttransfered” as a string when sending via net, and then read it as name, and then attempted to add a string to a number. Also, you tried to read a variable on the serverside when it was set clientside. You need to learn basic lua before you try and make a banking system.

What is it with French people and assuming they were right, and that the people they were seeking help from are wrong?

By the way your solution is horrible.
You’re using the most expensive way to transfer data when you could just send a single number. You should really use

net.WriteInt and

net.ReadInt instead

Thanks you very much