VGUI works for some players but not others

So I have made a gui for my players to be able to paint their cars different colours.
But the problem is it only works for some players and not others. I.e it works fine for me but my mate gets this error:


[ERROR] gamemodes/potato/gamemode/vgui/new_customise.lua:56: attempt to concatenate a nil value
  1. DoClick - gamemodes/potato/gamemode/vgui/new_customise.lua:56
   2. unknown - lua/vgui/dlabel.lua:232


Which in the code below is in the DoClick function where it is attempting to index the colour table from the mixers value.



local PANEL = {};

function PANEL:Init ( )
	isopen = true
	Car = nil
	for k, v in pairs(ents.GetAll()) do
        if v:IsVehicle() and (v:GetNetworkedEntity("owner") == LocalPlayer()) then
        	Car = v
        end
	end

	w, h = ScrW(), ScrH()
    DermaPanel = vgui.Create( "DFrame" )
	DermaPanel:SetPos( 0, 0 )
	DermaPanel:SetSize( w, h )
	DermaPanel:SetTitle( "" )
	DermaPanel:SetVisible( true )
	DermaPanel:SetDraggable( false )
	DermaPanel:ShowCloseButton( true )
	DermaPanel:MakePopup()
	DermaPanel.OnClose = function()
        isopen = false
	end

	Mixer = vgui.Create( "DColorMixer", DermaPanel)
	Mixer:SetPos((w/4)*3, (h/3)*2)
	Mixer:SetSize(w/4,h/4)
	Mixer:SetPalette( true ) 		--Show/hide the palette			DEF:true
	Mixer:SetAlphaBar( false ) 		--Show/hide the alpha bar		DEF:true
	Mixer:SetWangs( true )			--Show/hide the R G B A indicators 	DEF:true
	Mixer:SetColor( Color( 30, 100, 160 ) )	--Set the default color

	CarModel = vgui.Create ("DModelPanel", DermaPanel)
	CarModel:SetPos( w/8, h/8 )
    CarModel:SetSize( (w/3)*2, (h/3)*2 )
    CarModel:SetModel(Car:GetModel())
	CarModel:SetFOV( 45 )
	CarModel:SetCamPos( Vector( 0, 250, 200 ) )
	CarModel:SetLookAt( Vector(0, 0, 0) )
	CarModel:SetColor(Mixer:GetColor())

	id = Car:GetNetworkedString("vtableid");

	colours = tostring(Mixer:GetColor())
	colours = string.Split(colours, " ")

	SetColour = vgui.Create("DButton", DermaPanel)
	SetColour:SetPos((w/8) * 6, (h/12)*11)
	SetColour:SetSize(w/16, h / 16)
	SetColour:SetText("Confirm")
	SetColour.DoClick = function() 
	    LocalPlayer():ConCommand("potato_pimp_colour " .. tostring(id) .. " " .. colours[1] .. " " .. colours[2] .. " " .. colours[3]);
	    isopen = false;
	    DermaPanel:Close()
     end
end

function PANEL:PerformLayout ( )

end

function PANEL:Paint ( )

end


function PANEL:Think()
	if isopen == true then
		if CarModel and Mixer and CLIENT then
	        CarModel:SetColor(Mixer:GetColor())
	    end
	    if colours then
	        colours = tostring(Mixer:GetColor())
		    colours = string.Split(colours, " ")
		end
	end
end

vgui.Register("new_customise", PANEL);


I added some print debug statements for the id, and the colours and for him it returned this:



a -- The vehicleid
table:-- This part should be the colours
0x401a93e0
nil



Any ideas? thanks.

Oh god, localise those variables. Why on earth are you are creating a DermaPanel every time this vgui element is open and parenting everything to that rather than the vgui element itself? When registering an element just define DFrame at the end since thats what you want



vgui.Register("new_customise", PANEL, "DFrame")


In PANEL:Think you are checking if the code is ran on the client… in a vgui element?..
You are trying to check global variables when you could just define the variables on the element itself (element.Color)



function PANEL:Think()
	if isopen == true then
		if CarModel and Mixer and CLIENT then <---- What?
	        CarModel:SetColor(Mixer:GetColor())
	    end
	    if colours then
	        colours = tostring(Mixer:GetColor())
		    colours = string.Split(colours, " ")
		end
	end
end


I assume your trying to change the variable ‘color’ every time the mixer is changed so why not just use the OnValueChanged function for your colour mixer and change color to that and set it on the DModelPanel