Networking is not-working?

Im not sure if my game is starting to break apart or not but I have had ALOT of issues with stuff lately that neither I or anyone else seem to know how to solve.
Here is another one for ya!

Im trying to network the global variables from server to client, when sending them it sends 100 but when recieved it always gets a random value from (0 - 7) and I dont have any code that could be causing that.


util.AddNetworkString( "Slemp:NetInfo" )
net.Start( "Slemp:NetInfo" )
net.WriteEntity( v )
net.WriteInt( v.Temp,32 )
net.WriteInt( v.Tired,32 )
net.WriteInt( v.Sleeping,32)
net.Send( v )
-- Returns 100, 100, 1

net.Receive( "Slemp:NetInfo", function()
ply = net.ReadEntity()
ply.Temp = net.ReadInt(32)/100
ply.Tired = net.ReadInt(32)/100
ply.Sleeping = net.ReadInt(32)
end )
-- First two are random values from 0 to 7 and the last one returns 1.

The second argument to

net.WriteInt is a bitcount, it must be at least log-base-2(largest_number_you_want_to_send).

I guess you’ve thought the second argument of net.WriteInt as a slot number but it is bitcount of the int you are sending. try 32 for second argument if you dont know what to type and read with same order in client.


local doxamount = 282736
local doxcadillac = 000997
   net.WriteInt(doxamount, 32)
   net.WriteInt(doxcadillac, 32)

net.Receive("doxin", function()
    local doxamount = net.ReadInt()
    local doxcadillac = net.ReadInt()

Yeah - here are examples of bit counting:

Also, to save yourself setting up networking the long way each time you change a var - why not create a simple net system:

Here’s an example:

Then create a function META_PLAYER:IsTired( ) return self:GetFlag( “tired”, false, true ); end so they’re only set / get in one function with the key…

How it is set up - if you use data:G/SetFlag then it is ( _entindex, _flag, _value_default, _private_category )…
– _p:SetFlag( _flag, _value, _private, _category )
– _p:GetFlag( _flag, _default, _private, _category )

_flag is the name of the variable, _value is what you set it to ( you can spam these functions by the way - it only networks when the data changes ), _default is what to return if the var isn’t set, _private determines how it is networked ( If these functions are called on client, then no networking happens regardless of private… if called on server and not private, the data is broadcast to all if the value has changed… if private and setting the data to an entity, only the ent owner and server gets the data - if vehicle then only vehicle driver and server knows the data, if player then only player and server knows ), and _category is you want to sub-categorize the flags… ie if you want to have a _flag which is the same name for 2 different things on the same player - you can categorize it… so _p:SetFlag( “health”, 100, true, “armor” );_p:SetFlag( “health”, 100, true, “player” ); although in normal cases you’d simply use armor and health, but as an example…

Creating something like this will save a ton of time!

Also, for global vars, I use the map entity ( id 0 ) or game.GetWorld( ):S/GetFlag( … ); for things such as server ip, etc… vehicles spawned list, and so on… Things everyone needs to know related to the game…

This is the lightweight version, full version is something else… But it still works and is still v

I did what you told me to do but it doesn’t seem like it changed anything. (Edited code in first post)

Edit: I remade the entire script and now it works for some reason.