Hello, I am creating an alert addon that allows a player to open a menu, type an alert, and send it to the admins on the server. But I am encountering a problem on the player receiving the alert. When the player sends the alert it shows on his screen fine, but on the player the receives the alert gets the script error listed below. I will provide some code that should give you a gist of what you need to know.
Script error:
[lua]
[ERROR] addons/a-menu/lua/autorun/am_menu.lua:121: attempt to index global 'ipw' (a nil value)
1. func - addons/a-menu/lua/autorun/am_menu.lua:121
2. unknown - lua/includes/extensions/net.lua:32
[/lua]
Code:
[lua]
--[[Client side:]]--
net.Receive("writeinfo",function() --Function that sends the input of the player making the alert and sends it server side.
ipw = vgui.Create("DTextEntry",ip)
ipw:SetSize(490,230)
ipw:SetMultiline(true)
ipw:SetPos(5,30)
local ipwb = vgui.Create("DButton",ip)
ipwb:SetSize(100,30)
ipwb:SetPos(0,265)
ipwb:CenterHorizontal()
ipwb:SetText("")
ipwb.DoClick = function()
if ipw:GetValue() == "" then
LocalPlayer():ChatPrint(am.TextNoInput)
else
net.Start("preventmulti") --Not important
net.SendToServer()
net.Start("telltheworld")
net.SendToServer()
net.Start("sendalert")
net.WriteString( ipw:GetValue() )
net.SendToServer()
ip:SetVisible(false)
end
end
end)
net.Receive("alertmenu",function() --menu that popsup on the players screen displaying the msg
local aptp = vgui.Create("RichText",ap) --vgui using the inputted text
aptp:SetSize(ap:GetWide()-10,90)
aptp:SetPos(5,30)
aptp:AppendText(ipw:GetValue()) --LINE THE ERROR IS REFERRING TO
end)
net.Receive("telltheworld",function(len)
local text = net.ReadString()
ipw:AppendText( text.."\n")
end)
--[[Server side]]--
net.Receive("telltheworld",function(len,ply)
local text = net.ReadString()
net.Start("telltheworld")
net.WriteString(text,32)
net.Broadcast()
end)
net.Receive("sendalert",function(_,ply)
if table.HasValue( am.AdminInfoGroups, ply:GetUserGroup()) then
net.Start("alertmenu")
net.Broadcast(ply)
end
end)
[/lua]
The function in your alertmenu net receiver is called before you've made the ipw element you're calling GetValue on.
Sorry, you need to Log In to post a reply to this thread.