Question about server/client

Alright, so I’m making this question npc thingy, but i keep getting this error. It obviously has to do with serverside/clientside, but i cannot quite figure it out. Could anyone please help?



local TextEntry = vgui.Create( "DTextEntry", Frame )	
TextEntry:SetPos( 65, 49 )
TextEntry:SetSize( 75, 25 )
TextEntry:SetText( "Yes/No" )
TextEntry.OnEnter = function( self, ply )
	if self:GetValue() == "Yes" then
	chat.AddText("Correct!")
	ply:SetNWBool( "question1_true", true)
	else
	chat.AddText("Wrong!")
end


Error:



attempt to index local 'ply' (a nil value)



Thanks for your help.

Just use LocalPlayer()

Then what do i do if i want to read the NWBool using GetNWBool serverside? That just returns “LocalPlayer() a nil value”

Depending on what function you are calling it on serverside, you use ply generally for serverside and LocalPlayer for client side.

Alright, so i did this clientside:



local TextEntry = vgui.Create( "DTextEntry", Frame )	
TextEntry:SetPos( 65, 49 )
TextEntry:SetSize( 75, 25 )
TextEntry:SetText( "Yes/No" )
TextEntry.OnEnter = function( self, ply )
	if self:GetValue() == "Yes" then
	chat.AddText("Correct!")
	LocalPlayer():SetNWBool( "question1", true)
	else
	chat.AddText("Wrong!")
end


But when i try and get the NWBool serverside, it just returns false no matter what:



function AddStaff(ply)


print(ply:GetNWBool("question1"))



end
concommand.Add( "BoolTest", AddStaff )


What could i be doing wrong?

SetNW* functions on client DON’T send changes to server. You’ll have to use netmessages probably.

-snip I’m dumb-

Yeah, so i tried that:



local TextEntry = vgui.Create( "DTextEntry", Frame )	
TextEntry:SetPos( 65, 49 )
TextEntry:SetSize( 75, 25 )
TextEntry:SetText( "Yes/No" )
TextEntry.OnEnter = function( self, ply )
	if self:GetValue() == "Yes" then
	chat.AddText("Correct!")
	net.Start("question_1", false)
	net.SendToServer()
	else
	chat.AddText("Wrong!")
end


I keep getting



Calling net.Start with unpooled message name! [http://goo.gl/qcx0y]



Never mind, i found out why. I forgot to add


util.AddNetworkString( "question_1" ) 

[DEL]You must pool the message name. http://wiki.garrysmod.com/page/util/AddNetworkString[/DEL]

got ninja’d by an edit

-snip, Late again-

:snip: Ninja’d.

3 people all trying to rectify one error that could’ve been prematurely solved by simply following the link given in the error -.-

How would i go about reading that NWBool then?

I tried doing this serverside:



function GetInfo(pl)
	
	print(pl:GetNWBool("question_1_correct"))

end

	concommand.Add("Question_Answer", GetInfo)


It just always returns false.

Edit: Found out why :stuck_out_tongue: