SWEP Customize-able

Hello, I have been stuck for the last day or two. I have made a SWEP that throws a prop. However I wanted to be able to customise it in game without editting the lua file. I have tried making it use a menu to select the color but I have not been successful. I was wondering if anyone will be able to help me complete is code or will be willing to give me theirs.

SWEP LUA



if (SERVER) then --the init.lua stuff goes in here
   SWEP.Weight = 5;
   SWEP.AutoSwitchTo = false;
   SWEP.AutoSwitchFrom = false;
 end
 
if (CLIENT) then --the cl_init.lua stuff goes in here
 
 
   SWEP.PrintName = "Trail Gun";
   SWEP.Slot = 3;
   SWEP.SlotPos = 1;
   SWEP.DrawAmmo = false;
   SWEP.DrawCrosshair = false;
 
end
include("color.lua")
prop = "models/props_junk/PopCan01a.mdl"
 
SWEP.Author = "Jimbo";
SWEP.Purpose = "Throw Props Trails ";
SWEP.Instructions = "Left click to throw prop!";
SWEP.Category = "Prop Launchers"
 
SWEP.Spawnable = true;
SWEP.AdminSpawnable = true;
 
SWEP.ViewModel	= "models/weapons/c_arms.mdl";
SWEP.WorldModel = "";
 
SWEP.Primary.ClipSize = -1;
SWEP.Primary.DefaultClip = -1;
SWEP.Primary.Automatic = false;
SWEP.Primary.Ammo = "none";
SWEP.Primary.Delay = 2;
 
SWEP.Secondary.ClipSize = -1;
SWEP.Secondary.DefaultClip = -1;
SWEP.Secondary.Automatic = false;
SWEP.Secondary.Ammo = "none";





 
local ShootSound = Sound ("Metal.SawbladeStick");
 

function SWEP:Reload()
end
 
function SWEP:Think()
end

function SWEP:throw_attack (model_file)
	

	local tr = self.Owner:GetEyeTrace();
 

	self:EmitSound (ShootSound);
	self.BaseClass.ShootEffects (self);
	if (!SERVER) then return end;
 

	local ent = ents.Create ("prop_physics");
	ent:SetModel (model_file);
	ent:SetCollisionGroup(11)
 

	ent:SetPos (self.Owner:EyePos() + (self.Owner:GetAimVector() * 8));
	ent:SetAngles (self.Owner:EyeAngles());
	ent:Spawn();
 
	if ChosenColor==nil then
		color = Color(255,0,0)
	else
		color = ChosenColor
	end
 
 
 
	trail = util.SpriteTrail(ent, 0, color, false, 15, 1, 4, 1/(15+1)*0.5, "trails/plasma.vmt")
	local phys = ent:GetPhysicsObject();
 

	local shot_length = tr.HitPos:Length();
	phys:ApplyForceCenter (self.Owner:GetAimVector():GetNormalized() *  Vector(500,600,500):Length());
 

	cleanup.Add (self.Owner, "props", ent);
 
	undo.Create ("Thrown chair");
	undo.AddEntity (ent);
	undo.SetPlayer (self.Owner);
	undo.Finish();
	SafeRemoveEntityDelayed( ent, 4 );
	print(color)
end
 

function SWEP:PrimaryAttack()
	self:SetNextPrimaryFire(CurTime()+4);

	self:throw_attack (prop);

end

function SWEP:SecondaryAttack()
end


Menu Lua




function testpanel() -- Create the function
if (!SERVER) then return end;
local Frame = vgui.Create( "DFrame" )
Frame:SetPos( 5, 5 )
Frame:SetSize( 300,400 )
Frame:SetTitle( "Shitty Thing" )
Frame:SetVisible( true )
Frame:SetDraggable( false )
Frame:ShowCloseButton( true )
Frame:MakePopup()


local ColorPicker = vgui.Create( "DColorMixer", Frame )
ColorPicker:SetSize( 200, 200 )
ColorPicker:SetPos( 50, 50 )
ColorPicker:SetPalette( true )
ColorPicker:SetAlphaBar( true )
ColorPicker:SetWangs( true )
ColorPicker:SetColor( Color( 255, 255, 255 ) )

local ConfirmColor = vgui.Create( "DButton", Frame )
ConfirmColor:SetText( "I want this color" )
ConfirmColor:SetSize( 90, 30 )
ConfirmColor:SetPos( 100, 270 )
ConfirmColor.DoClick = function()
	ChosenColor = ColorPicker:GetColor()
end
local Prop = vgui.Create( "DButton", Frame )
Prop:SetText( "Prop" )
Prop:SetSize( 90, 30 )
Prop:SetPos( 100,  Frame:GetTall() - 40 )
Prop.DoClick = function()
	prop = "models/Gibs/HGIBS.mdl"
end

end -- ending the function
concommand.Add("menutest", testpanel) -- adding the console command


Thanks in advance!

I would like to point out that you’re changing a global variable called “prop” and “ChosenColor”. Globalizing them is a bad practise and you should have the menu code and the SWEP’s code in the same Lua file. Also, localize your variables called “prop” and “ChosenColor”, or they will and can be edited by other scripts, causing overlaps.

Also, be more specific with your problem.
Errors?
What’s happening?
What should be happening?

When I open the menu. I should be able to choose a color which it does. But it doesn’t change the color of the trail.