Something causing errors in the net libary

Error doesn’t seem related.

They aren’t global variables, at least in the last post you made with the code.

SQL isn’t bad, it’s a great system for storing data. However, the choice of using files or a database usually won’t make much of a difference depending on the application.

I still have no clue why im getting those errors. Is the network connection wrong or my code? :smiley:

Those errors you posted are unrelated as far as I can tell. Unless you’re getting another error that’s erroring a hook, I’d suggest removing pointshop and testing it again.

It’s most likely the code I wrote, because after I delete it from the server everything works fine.
But when its on the server I get the errors and nothing works.

That’s why I’m suggesting removing pointshop. From what I can tell it’s spamming those errors making it impossible to see any of the errors your own code produces.

You’re right, I found this
[LUA]
[ERROR] addons/advancedtpass/lua/autorun/server/sv_data.lua:18: bad argument #1 to ‘WriteInt’ (number expected, got nil)

  1. WriteInt - [C]:-1

  2. fn - addons/advancedtpass/lua/autorun/server/sv_data.lua:18

3. unknown - addons/ulib/lua/ulib/shared/hook.lua:109

[:heart: [NewByte] Dagun :heart:|2|STEAM_0:0:49150310] Lua Error:

[ERROR] addons/advancedtpass/lua/autorun/client/cl_panel.lua:1: attempt to call field ‘AddNetworkString’ (a nil value)

  1. unknown - addons/advancedtpass/lua/autorun/client/cl_panel.lua:1
    [/LUA]

[editline]28th January 2017[/editline]

So the first error doesn’t make sense in my eyes because TAmount is defined and its not nil

And the second error makes much more non-sense in my eyes.

Server
[LUA]
if file.Exists(userDataFile, “DATA”) then
local playerData = util.JSONToTable(file.Read(userDataFile, “DATA”) )
local TAmount = playerData.TAmount
local DAmount = playerData.DAmount
net.Start(“passdata123T”)
net.WriteInt(TAmount,32)
net.Send(ply)
net.Start(“passdata123D”)
net.WriteInt(DAmount,32)
net.Send(ply)
else
[/LUA]

Client

[LUA]
util.AddNetworkString(“sendMinusValueT”)
util.AddNetworkString(“sendMinusValueD”)
[/LUA]

[editline]28th January 2017[/editline]

Maybe I loaded the files wrong or maybe I did something else.

Is [LUA] playerData.TAmount [/LUA] wrong?

It basicly loads from a lua table.

util.AddNetworkString is a serverside function. And that error implies that, for whatever reason, playerData.TAmount is loading as nil.

Cant figure out why it is a nil value.
The file is on the server with the value 0,

Im confused I need to fix it somehow.

Basicly I removed the JSON table and because I am lazy right now I just wrote a code that saves 2 files for 1 player and the connection “works” I think because I don’t get any error message because of the network. But now I have this error.

Error:
[LUA]
[ERROR] addons/advancedtpass/lua/autorun/server/sv_data.lua:74: attempt to perform arithmetic on global ‘TAmount’ (a nil value)

  1. func - addons/advancedtpass/lua/autorun/server/sv_data.lua:74

  2. unknown - lua/includes/extensions/net.lua:32
    [/LUA]

Lines of code
[LUA]

net.Receive(“sendMinusValueT”, function(len,ply)
if(net.ReadString(4) == “yes”) then
local TAmount = 0
net.Start(“passdata123T”)
net.WriteInt(TAmount,32)
net.Send(ply)
else
local TAmount = TAmount - net.ReadInt(32)
net.Start(“passdata123T”)
net.WriteInt(TAmount,32)
net.Send(ply)
end
end)

net.Receive(“sendMinusValueD”, function(len,ply)
if(net.ReadString(4) == “yes”) then
local DAmount = 0
net.Start(“passdata123D”)
net.WriteInt(DAmount,32)
net.Send(ply)
else
local DAmount = DAmount - net.ReadInt(32)
net.Start(“passdata123D”)
net.WriteInt(TAmount,32)
net.Send(ply)
end
end)

net.Receive(“sendPlusValueT”, function(len,ply)
local TAmount = TAmount + net.ReadInt(32)
net.Start(“passdata123T”)
net.WriteInt(TAmount,32)
net.Send(ply)
end)

net.Receive(“sendPlusValueD”, function(len,ply)
local DAmount = DAmount + net.ReadInt(32)
net.Start(“passdata123D”)
net.WriteInt(DAmount,32)
net.Send(ply)
end)
[/LUA]

[editline]29th January 2017[/editline]

It is a global variable? Where?

They aren’t global because you’re defining each one as local, do you not see that?

Also if you make these global, they’re going to conflict when more than once player is on the server.

[LUA]attempt to perform arithmetic on global ‘TAmount’[/LUA]

I mean it says its global, I know its supposed to be local

You’re doing



local TAmount = TAmount - net.ReadInt(32)


but TAmount isn’t defined in the local scope before this operation, as such it looks in the global scope, because it’s not there either it errors.

I’d suggest you learn a little bit about Lua