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 )
LocalPlayer():SetNWString(gender,“Male”)
end

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

function ReadGender()

 for k, v in pairs(player.GetAll()) do
 
	 v:ChatPrint(v:GetNWString(gender))
	 
 end

end

function GM:initialize()

 timer.Simple( 100, ReadGender )

end

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
[lua]–init.lua
concommand.Add( “setgendermale”, function( ply, cmd, arg )

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

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

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.

[editline]12:40AM[/editline]

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

thanks i’ll test it now

[editline]03:59PM[/editline]

it works thanks.

Use lua tags next time you post code


[lua][/lua]