• bad argument #2 to 'WriteInt' (number expected, got no value)
    3 replies, posted
Hey, so I'm trying to make something for DarkRP, however when the players get the money, this error comes up: bad argument #2 to 'WriteInt' (number expected, got no value) This is my server side code: net.Receive( "Pay", function(len, ply)     local sub = net.ReadEntity()     local pay = net.ReadInt()     if ply:IsPlayer() and ply:IsValid() then         ply:addMoney( pay )     end     if sub:IsValid() and sub:IsPlayer() then         if sub:getDarkRPVar("money") >= pay then             sub:addMoney( -pay )         end     end end) And this is the client side: hitoptions:AddOption( "Accept Money", function()             for k, v in pairs(pricetable) do                 local sub = v.submitter                 local pay = v.price -- This printed in console fine.                 net.Start( "PayForHit" )                     net.WriteEntity( sub )                     net.WriteInt( pay )                 net.SendToServer()             end end)
you didn't append the bitcount net.WriteInt( number integer, number bitCount )
net.WriteInt requires 2 arguments: the number (which you're providing just fine), and bit count. You should set the bit count to some constant based on the range of values you want to be able to send. For example, if 'pay' is always within the range -32,768 < pay < 32,767, you can use 16 bits. Consult the table linked in the wiki page, but notice that you have to take one extra bit from the one in that table. net.ReadInt must have the same bit count argument as net.WriteInt.
Okay, so I've done this, and still doesn't seem to work. Client: priceops.DoDoubleClick = function( p, s ) priceoptions:AddOption( "Accept Money", function()             for k, v in pairs(pricetable) do                 local sub = v.submitter                 local pay = v.price                 net.Start( "PayForMoney" )                     net.WriteEntity( sub )                     net.WriteInt( pay, 16 )                 net.SendToServer()             end end) end For server side: net.Receive( "PayForMoney", function(len, ply)     local sub = net.ReadEntity()     local pay = net.ReadInt(16)     ply:addMoney( pay )     if sub:IsValid() and sub:IsPlayer() then         if sub:getDarkRPVar("money") >= pay then             sub:addMoney( -pay )         end     end end)
Sorry, you need to Log In to post a reply to this thread.