Problems with Tool Cpanels

So I’m trying to make a stool that explodes where you click, with a slider to change the explosions’s radius. However, no matter what I do I cannot fathom how to properly set the radius though the slider. I’ve tried splicing many different things from other STools, but they’re often different and confusing, and STools on the wiki lack proper documentation compared to say, SWEPS.
Can someone either fix my code or tell me a simpler way around this please?

The error:


edownloading all lightmaps
[@gamemodes\sandbox\gamemode\spawnmenu\controlpanel.lua:99] ControlPanelBuildFunction Error: [@lua\includes\extensions	able.lua:421] bad argument #1 to 'pairs' (table expected, got nil)


The STool code:


 
TOOL.Category = "Admin Events"
TOOL.Name = "Exploder"

TOOL.Command = nil
TOOL.ConfigName = "" --Setting this means that you do not have to create external configuration files to define the layout of the tool config-hud 

TOOL.RequiresTraceHit = false
TOOL.ClientConVar[ "ERad" ] = 30
if CLIENT then

language.Add("Tool_explosion_name","Exploder")
language.Add( "Tool_explosion_desc","Create a an explosion for events.")
language.Add( "Tool_explosion_0","Fire to create an explosion at the point with a given radius.")

end
function TOOL:LeftClick( tr )
if not self:GetSWEP().Owner:IsAdmin() then return end
local exp = ents.Create( "env_explosion" )
exp:SetKeyValue( "magnitude", GetConVarNumber("ERad"))
exp:SetPos(tr.HitPos)
exp:Spawn()
exp:Activate()
end
 
function TOOL:RightClick( tr )
return true
end
function TOOL:Reload()

end
/*
function explodrad(player,command,args)
self.ERad=args[1]
end*/

function TOOL.BuildCPanel( CPanel)

CPanel.AddControl( "Header", { Text = "#Tool_toolname_name", Description = "#Tool_toolname_desc" }  )

	local params = { Label = "#Presets", MenuButton = 1, Folder = "explosion", Options = {}, CVars = {} }
		
		params.Options.default = {
			explosion_ERad			=		30
		}
table.insert( params.CVars,"explosion_ERad")
CPanel:NumSlider( "#Explosion Radius", "explosion_ERad", 1, 500, 1)
	/*CPanel:AddControl( "Slider", { Label = "Explosion Radius",
									 Description = "",
									 Type = "Float",
									 Min = 1,
									 Max = 500,
									 Command = "exploderad" } )*/
end
 
--Add the concommand line
//concommand.Add("explodrad",explodrad)


gamemodes\sandbox\gamemode\spawnmenu\controlpanel.lua:99
lua\includes\extensions able.lua:421

Get the code around those two lines and we might beable to help you more.

[lua]TOOL.Category = “Admin Events”
TOOL.Name = “Exploder”

TOOL.Command = nil
TOOL.ConfigName = “”

TOOL.RequiresTraceHit = false
TOOL.ClientConVar[ “ERad” ] = 30
if CLIENT then
language.Add(“Tool_explosion_name”,“Exploder”)
language.Add( “Tool_explosion_desc”,“Create a an explosion for events.”)
language.Add( “Tool_explosion_0”,“Fire to create an explosion at the point with a given radius.”)
end
function TOOL:LeftClick( tr )
if not self:GetOwner():IsAdmin() then return end

local exp = ents.Create( "env_explosion" )
exp:SetKeyValue( "iMagnitude", GetConVarNumber("explosion_ERad"))
exp:SetPos(tr.HitPos)
exp:Spawn()
exp:Activate()
exp:Fire("Explode", "", 0)

end

function TOOL:RightClick( tr ) return false end
function TOOL:Reload() return false end

/*
function explodrad(player,command,args)
self.ERad=args[1]
end*/

function TOOL.BuildCPanel(CPanel)

CPanel:AddControl( “Header”, { Text = “#Tool_explosion_name”, Description = “#Tool_explosion_desc” } )

local params = { Label = "#Presets", MenuButton = 1, Folder = "explosion", Options = {}, CVars = {} }
	
	params.Options.default = {
		explosion_ERad			=		30
	}

table.insert( params.CVars,“explosion_ERad”)
CPanel:NumSlider( “#Explosion Radius”, “explosion_ERad”, 1, 500, 1)
/CPanel:AddControl( “Slider”, { Label = “Explosion Radius”,
Description = “”,
Type = “Float”,
Min = 1,
Max = 500,
Command = “exploderad” } )
/
end

–Add the concommand line
//concommand.Add(“explodrad”,explodrad)[/lua]

The modified script should work, tested it and it worked when i tried it, I’ve also tidied up your code a little. The piece of code causing the error was when building the header for your CPanel, you used:

[lua]CPanel.AddControl[/lua]

instead of:

[lua]CPanel:AddControl[/lua]

I also fixed the problem with env_explosion. Your code did not activate the explosion, and the radius convar was not being read. I changed the right click/reload functions to return false, as they should be if you’re not going to do anything with them. If you return true, it will display the ingame ‘click’ effect and sound as if it’s actually done something. Finally I have changed this line:

[lua]if not self:GetSWEP().Owner:IsAdmin() then return end[/lua]

to:

[lua]if not self:GetOwner():IsAdmin() then return end[/lua]

Both work, but the direct and best way to do it is to use the latter piece of code.