up-to-date network variable

HI there, more questions:

I have an SQLite table happening, and I have NW variables fetching values from the table.

in the scenario of an RP mod where all the players have different values, how would I go about fetching a value for each player? I can do it for one player, but wouldn’t the NW variable be the same variable for all players (ie, if someone updated the money on their HUD, everyone’s hud would show THEIR money)? or have I got this all wrong?

I want to use a NW variable to show the amount of cash in the player’s wallet on their HUD, but from what i’ve learnt, the server has to set the value of the NWvar in order for it to be updated on the client. Also, how would I keep it up to date?

Is this the best way of doing something like this?

It wouldn’t be updating everyones because if its like player:SetNWInt(“money”, 200) its only setting that player’s Networked money variable.

oh ok, cool.

can I do SetNWInt on the client?


No, if you could, then everyone could change their money.

good point.

You can use SetNWVar on the client, but it doesn’t get sent to the server.

There’s only two real ways to send info from the client to the server and that’s using datastream or using console commands. Even though datastream uses console commands, it makes sending info much easier.

so what would I put in a script that shows the amount of money on the client’s HUD?

The only real use for the datastream is for sending large (saved) tables to clients. Anything else, just use concommands or usermessages.

You would use Gamemode.HUDPaint.

But I thought if you change the file the server will just redownload it and you will have to use the new downloaded file.

How are files related to networked variables?

You said then everyone could change their money. They couldn’t if the server redownloaded the file erasing the code where they could change their money.

Then they’d just run some client-side lua in the console or in the lua folder, but it’s not like it matters since clients can’t use SetNWVar to change data on the server, all they can do is change their money display.

Oh yea I guess that’s true :open_mouth:

And with script enforcer, they could still use memory modification techniques. Moral of the story: Never trust the client on something.

How does that answer my question :S

I know how to DRAW it, I don’t know what to use to show a variable that is “up to date”, as in, do I put a NWString on a timer that sets it every second, and use GetNWString to read it on the hud? Because right now, the function that paints my HUD seems to only want to return ply as being nil.


And that would mean a database call would be made every second.

You use GetNWString to draw it on the HUD and SetNWString whenever the value changes.

In your HUDPaint function it is called every frame rate. So it keeps redrawing the number.

your local ply would be. local ply = LocalPlayer()
and your points would be local points = LocalPlayer():GetNWString()

Look here for the clientside of things.

Look here at surface for drawing the values onto the screen.

edit* ghosted