How can I show my Variables ?

In init.lua

function GM:PlayerInitialSpawn( ply )

	for k, v in pairs(player.GetAll()) do
		v.oil = 10 -- everyone have variables  "oil" 

In cl_init.lua

function GM:HUDPaint()
	draw.SimpleText(LocalPlayer().oil, "ScoreboardText", ScrW() / 2 - 70, ScrH() - 63, Color(255,255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)

It’s not work? why?

and How can I improve it ?

The GM:PlayerInitalSpawn is being called everytime a player loggs on ur server.
so you can just do ply:oil = 10, and thats it.

You cannot access serverside variables from the client, you must network them.
Take a look at this page…

PlayerInitialSpawn is a server side function, and you’re appending to the player’s object server side, yet attempting to access it from the client by drawing it. Instead of setting it as a variable, use NetworkedVars to allow any client to access a player’s variable with the same indentifier.
Server side:
[lua]function GM:PlayerInitialSpawn( ply )

ply:SetNWInt( "oil", 10 )


Client side:
[lua]function GM:HUDPaint()

draw.SimpleText( LocalPlayer():GetNWInt( "oil" ), "ScoreboardText", ScrW() / 2 - 70, ScrH() - 63, Color(255,255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER) )


thx very much!!!

you are friendly!!

Just a note: NWBools, NWStrings, and NWInts do not save after someone leaves the server.

what can save?

Use PData,
[lua]player:SetPData( “my_bool”, true )
local bool = player:GetPData( “my_bool” )[/lua]
It’s saved onto the server’s sqlite database.

[editline]31st May 2014[/editline]

Also, make sure you don’t keep spamming it often, since it’s querying a database.
Try saving PData every 5 minutes or so and when the player disconnects from the server (use the PlayerDisconnected hook) and use NWVars while the player is on the server.

thanks you very much Internet1001

You are like my teacher

when I have problems you always help me

Sorry,my English is not so good

I am a Taiwanese

Can I be friend with you?

I can be your friend but it depends on your gender.

I think it’s also worth noting that you should use hook.Add in situations like this.
For example:
function GM:PlayerInitialSpawn( ply )
ply:SetNWInt( “oil”, 10 )
should become
– The second string should be something that’s “unique”.
hook.Add( “PlayerInitialSpawn”, “weixin0914_PlayerInitialSpawn”, function(ply)
ply:SetNWInt( “oil”, 10 )

This is because, when you’re just doing GM:PlayerInitialSpawn, all other addons that use that function cannot use it. Using hook.Add makes sure that everyone can use it.

No offense, but you don’t really know how to code, stop helping people, and at least speak English and spell the hook right.