Problem with converting datastream to net

Well i have a old car script that i tryed to convert from datastream to net but i failed.
I hope someone can help me(preferably with teamviewer).

The problem is if i click on the cars button(in my menu) i get this error:


[ERROR] addons/thephoenixservers/lua/autorun/client/cl_tpsmenu.lua:822: bad argument #1 to 'pairs' (table expected, got nil)
  1. pairs - [C]:-1
   2. tps_ShowCarsMenu - addons/thephoenixservers/lua/autorun/client/cl_tpsmenu.lua:822
    3. DoClick - addons/thephoenixservers/lua/autorun/client/cl_tpsmenu.lua:1127
     4. unknown - lua/vgui/dlabel.lua:206

this is in cl_tpsmenu where the error begins:


for k,v in pairs(TPS_CARS) do

and this is the line that needs to send the data to the menu, im almost sure that its wrong:
[LUA]
function carDatastream(handler,id,encoded,decoded)
TPS_CARS = decoded
end
net.Receive( “TPS_BASE_CARS”, function(carDatastream) end)
[/LUA]

i rated you dumb because wtf dude seriously?

also you will also need to post the code for sending the datastream so it can also be converted. noone can really help unless we know what is in the datastream in the first place.

sorry :frowning:


net.Receive( "TPS_BASE_CARS", function(carDatastream) end)

that obviously doesn’t do anything.
You have to do it like that to use the above function.


net.Receive( "TPS_BASE_CARS", carDatastream)

Also we can’t know where the error occurs because we don’t have the line numbers.

Oke ill paste the converted parts,

this is in serverside file that i converted:
[LUA]
function car.PlayerInitialize(ply)
if !IsValid(ply) then return end
if !ply.Cars then return end
print("////// [TPS] [Loading Player Cars] ///////")
print(ply:Nick()…"'s Cars: “…ply.Cars)
print(”//////////////////////////////////////////")
car.SendToClient(ply,ply.Cars)
car.Debug(ply,ply.Cars)
ply._is_going_out = CurTime()
//datastream.StreamToClients(ply, “TPS_BASE_CARS”, TPS_CARS)
net.Start( “TPS_BASE_CARS” )
net.WriteTable( TPS_CARS )
net.Send( ply )
end
[/LUA]

and this is the clientside i converted:
[LUA]
function car.Datastream(handler,id,encoded,decoded)
TPS_CARS = decoded
end
net.Receive( “TPS_BASE_CARS”, car.Datastream)
//datastream.Hook(“TPS_BASE_CARS”, car.Datastream)
[/LUA]

This is in the menu the line(822) to call the cars:
[LUA]for k,v in pairs(TPS_CARS) do[/LUA]

I hope this helps


TPS_CARS = decoded

Makes no sense because decoded and encoded will always be nil, try


TPS_CARS = net.ReadTable()

instead.

it worked
Thank you so much!