• attempt to call field 'Send' (a nil value) when sending a net message to player
    9 replies, posted
Hi guys, i'm trying to open a derma when a command is used so i'm using net messages the only problem is that when i try to send the net message to the local player i get a nill value. So those are my two client files: hook.Add( "OnPlayerChat", "OpenPA", function( ply, text )     if ply == LocalPlayer() and text == "!derma" then         net.Start("PAOpen")         net.WriteInt(2,16)         net.Send( LocalPlayer() )         return true     end end ) net.Receive("PAOpen", function(len, ply) local int = net.ReadInt(16) if int == 2 then     local Frame = vgui.Create( "DFrame" )         Frame:SetPos( 5, 5 )         Frame:SetSize( 1200, 800 )         Frame:SetTitle( "PA System 0.1" )         Frame:SetVisible( true )         Frame:SetDraggable( false )         Frame:ShowCloseButton( true )         Frame:Center()         Frame.Paint = function()             surface.SetDrawColor( 50, 50, 50, 255 )             surface.DrawRect( 0, 0, Frame:GetWide(), Frame:GetTall() )             surface.SetDrawColor( 130, 130, 130, 255 )             surface.DrawOutlinedRect( 0, 0, Frame:GetWide(), Frame:GetTall() )         end         Frame:MakePopup()     end end) and this is my server file: util.AddNetworkString( "PAOpen" ) I hope that someone know what is wrong with my code and can help me to fix it.
OnPlayerChat is a clientside hook and net.Send is a serverside function.
onplayerchat is already clientside. you shouldn't need to be using net.send at all for this if this is being done through clientside.
Then is there a serverside equivalent to OnPlayerChat ?
GM/PlayerSay the wiki does give you a serverside equivalent when looking at the onplayerchat wiki page. i suggest to look up on the wiki which should have prevented the need for a forum thread
so now i'm using playersay but it still give me the same error hook.Add( "PlayerSay", "OpenPA", function( ply, text )     if ply == LocalPlayer() and text == "!derma" then         net.Start("PAOpen")         net.WriteInt(2,16)         net.Send(ply)         return true     end end )
Not a chance you're getting the same error, but you're comparing ply to LocalPlayer(), which is a client-side only global. C'mon now...
sorry i'm kinda new to lua and didn't see that the error was different so this is what I get: attempt to call global 'LocalPlayer' (a nil value)
As stated LocalPlayer is clientside only, it has no use for serverside. You can just remove that part of the if-statement totally. Just check what the text is equal to instead
that was fixed the issue, thanks ^^
Sorry, you need to Log In to post a reply to this thread.