SpawnIcons

I’ve been trying to build a selection menu using Spawn Icons so when you click next or Previous the SpawnIcon changes, When using Print to check the value from the Table the model is right but the spawn icon Doesn’t change, Any help?

Note: tabbing messed up when I pasted it into here for some reason.

[lua]
local VehicleModel = {“models/buggy.mdl”,
“models/vehicle.mdl”,
“models/airboat.mdl”}
N = 1

local NextButton = vgui.Create( "DButton" )
        NextButton:SetParent( Select )
        NextButton:SetText("Next" )
        NextButton:SetPos( 156, ( ScrH() - 80 ) )
        NextButton:SetSize( 80, 20 )
        NextButton.DoClick = function()
	
    if N == 3 then
	    N = 1
       else
            N = ( N + 1 )
   end
	print( VehicleModel[N] )
       end
	
local PrevButton = vgui.Create( "DButton" )
        PrevButton:SetParent( Select ) 
        PrevButton:SetText("Prev" )
        PrevButton:SetPos( 20, ( ScrH() - 80 ) )
        PrevButton:SetSize( 80, 20 )
        PrevButton.DoClick = function()
    
    if N == 1 then
	    N = 3
       else
            N = ( N - 1 )
   end
	print( VehicleModel[N] )
       end

local VehicleIcon = vgui.Create( "SpawnIcon", Frame )
    VehicleIcon:SetParent( Select )
    VehicleIcon:SetIconSize( 128 )
        VehicleIcon:SetPos( 64, ( ScrH() - 232 ) )
        VehicleIcon:SetModel( VehicleModel[N] )

[/lua]

SetModel is only set once, upon initialization of this code. You need to set it again in the DoClick events.

Something like this:
[lua]local VehicleModel = {“models/buggy.mdl”,
“models/vehicle.mdl”,
“models/airboat.mdl”
}

N = 1

local VehicleIcon = vgui.Create( “SpawnIcon”, Frame )
VehicleIcon:SetParent( Select )
VehicleIcon:SetIconSize( 128 )
VehicleIcon:SetPos( 64, ( ScrH() - 232 ) )
VehicleIcon:SetModel( VehicleModel[N] ) – Initial model, before any button is pressed

local NextButton = vgui.Create( “DButton” )
NextButton:SetParent( Select )
NextButton:SetText(“Next” )
NextButton:SetPos( 156, ( ScrH() - 80 ) )
NextButton:SetSize( 80, 20 )
NextButton.DoClick = function()
if N == 3 then
N = 1
else
N = N + 1
end

VehicleIcon:SetModel( VehicleModel[N] ) -- Change the model when clicked

end

local PrevButton = vgui.Create( “DButton” )
PrevButton:SetParent( Select )
PrevButton:SetText(“Prev” )
PrevButton:SetPos( 20, ( ScrH() - 80 ) )
PrevButton:SetSize( 80, 20 )
PrevButton.DoClick = function()
if N == 1 then
N = 3
else
N = N - 1
end

VehicleIcon:SetModel( VehicleModel[N] ) -- Change the model when clicked

end[/lua]