Send amount from client to server

Hello,

how to send an amount from a cl_init.lua to a init.lua ?

for exemple:

cl_init.lua



local amount = 10
RunConsoleCommand("_sendamount", amount)


init.lua



function GotIt(ply, amount)

	ply:AddMoney(amount)
end
concommand.Add("_sendamount",GotIt)


So what i want here, is to send the amount (10) from cl_init.lua to init.lua and then Add this amount to the player.

But it doesnt work.

Can you explain me the right way to proceed ?

Try not to use console commands unless you want users to use them outside of Lua.

Instead, try:

[LUA]
–SERVERSIDE:

util.AddNetworkString(“sendamount”)
net.Receive(“sendamount”, function(length, ply)
ply:AddMoney(net.ReadInt())
end)

–CLIENTSIDE:
local amount = 50
net.Start(“sendamount”)
net.WriteInt(amount)
net.SendToServer()
[/LUA]

That’ll prevent players from running the console command when you don’t want them to.

Getting this error



 bad argument #2 to 'WriteInt' (number expected, got no value)




---------------------- EDIT --------------------------
I found the solution, thx for help.

concommands pass 3 arguments: player, command, args

Player is, obviously, the player that ran the command.
Command is the command you added (in this case, “_sendamount”)
Args is a table filled with strings- anything that comes after the command.

In this case, use the first index of args instead of “amount”. Keep in mind, relying on the client for adding money is a very very very very bad idea.