Timer Help

Ok so for my gamemode I need it to loop through all players and get the string that it stored for them after 100 seconds. Here is the code I have for storing the variable in cl_init.lua:
button = vgui.Create( “DButton”, frame )
button:SetPos( 200, 600)
button:SetSize( 100, 50 )
button:SetText( “Male” )
button.DoClick = function()
frame:SetVisible( false )

and here is what i put to read the variables in init.lua:

function ReadGender()

 for k, v in pairs(player.GetAll()) do


function GM:initialize()

 timer.Simple( 100, ReadGender )


I understand that this code may be completely wrong but I’m new to Lua so please help.
I also get no errors.

When you set a NWVar clientside it isn’t updated serverside.

oh thanks so what should i do?

You could create a concommand
concommand.Add( “setgendermale”, function( ply, cmd, arg )

ply:SetNWString( "Gender", "Male" )

end )[/lua]
button.DoClick = function()
frame:SetVisible( false )
RunConsoleCommand( “setgendermale” )

A better way to do it would be something along the lines of
[lua]concommand.Add( “setgender”, function( ply, cmd, arg )

ply:SetNWString( "Gender", arg[1] )

end )[/lua]
that’s just a basic example.


Also, it should be
[lua]v:ChatPrint(v:GetNWString( “gender” ))
–rather than
v:ChatPrint(v:GetNWString( gender ))[/lua]

thanks i’ll test it now


it works thanks.

Use lua tags next time you post code