• attempt to call method 'GetActiveWeapon' (a nil value)
    1 replies, posted
Hello everyone, The console give an error when i run this script: [ERROR] addons/teamsradion2/lua/radio/server/sv_init.lua:142: attempt to call method 'GetActiveWeapon' (a nil value)  1. unknown - addons/teamsradion2/lua/radio/server/sv_init.lua:142   2. unknown - lua/includes/modules/concommand.lua:54 Here is the code: concommand.Add("tr_switchchannel", function( pl ) if pl:GetActiveWeapon():GetClass() == "swep_radiodevice" and pl:GetWeapon( "swep_radiodevice" ):GetDeviceStatus() then if not pl.sc then pl.sc = true local chans = findChannels( pl ) if #chans > 1 then local curChan = pl:getDarkRPVar("channelID") curChan = table.FindNext( chans, curChan ) if curChan > table.GetLastKey(chans) then curChan = chans[1] end pl:setDarkRPVar("channelID", curChan) pl:setDarkRPVar("channelName", TeamRadio.radioChannels[curChan]["channelName"]) timer.Simple(0.5, function() pl.sc = false end) else pl:setDarkRPVar( "channelID",  tonumber(chans[1])) timer.Simple(0.5, function() pl.sc = false end) end end end end)
If you're calling the command from the server console, pl will be NULL. Check if it's valid before calling GetActiveWeapon on it.
Sorry, you need to Log In to post a reply to this thread.