Differences between ply.variable and NWVariable?

Hello
Excuse me for any grammatical errors.

I don’t understand when I have to use a NetWorkVar and when a variable like this “player.variable” (I don’t know which is the name of the last one).

What’s the difference between “Player:SetNWInt(“AnyVar”, 10)” and “Player.AnyVar = 10”

Thank you!

NW(2)Vars and NetworkVars/DTVars are variables that are networked from the server to client. Regular variables (player.variable) is just stored on the entity in the realm you declared it in.

All of the NW* functions (SetNWInt, SetNWBool, etc) stand for SetNetWorkedVar, meaning that the variable you set there (in your case, “AnyVar”) will be communicated to the client.

Normally, if I’m running serverside code and do


player.x = 1

and then try to get the value of “x” on the client, it won’t work.

Using the NW functions, I can do


player:SetNWBool("AnyVar", true)

and then use


player:GetNWBool("AnyVar")

on the client to see what the value is.

You can use player.AnyVar if you’re just storing data to use it later, but that will not make it available for the player it’s stored on—or other players on the server—to use.

Ok, last question:
I have read, somewhere, that is wrong use too much NWVars because these can cause the lag.
So, how can I know what’s the limit?

You should only use them when you need something to be networked uniquely to an entity and be predicted. For non-networked variables, use a regular entity variable (ent.foobar). For non-predicted variables, consider using the net library, instead.