Set Entity Skin for All Parts - Debug

Long story short I have some SEnts that use multiple models specified in the shared.lua (Chassis/Wheel/Etc.)

I need to be able to change the skin on the chassis, and have it automatically change it on the rest of the parts.

I’ve tried using this:



function ENT.SkinChanger()
    if self.CarModel:SetSkin(i) then 
    self.TireModel:SetSkin(i) and self.PipeModel:SetSkin(i) and self.TowerModel:SetSkin(i) 
    end
end


This:



function ENT.SkinChanger()
    if self.CarModel:SetSkin(i) then 
    self.TireModel:SetSkin(i) && self.PipeModel:SetSkin(i) && self.TowerModel:SetSkin(i) 
    end
end


And this:


function ENT.SkinChanger()
    for k, v in pairs( self.CarModel:GetSkin(i) ) do
        self.TireModel:SetSkin( k, v:GetSkin(i) )
        self.TowerModel:SetSkin( k, v:GetSkin(i) )
        self.PipeModel:SetSkin( k, v:GetSkin(i) )
    end
end

This too:


function ENT.SkinChanger()
    if self.CarModel:GetSkin(0) then 
        self.TireModel:SetSkin(0)
        self.PipeModel:SetSkin(0)
        self.TowerModel:SetSkin(0) 
    elseif self.CarModel:GetSkin(1) then
        self.TireModel:SetSkin(1)
        self.PipeModel:SetSkin(1)
        self.TowerModel:SetSkin(1) 
    end
end

This:


function ENT.SkinChanger()
    for k, v in ipairs( self.CarModel:GetSkin(i) ) do
        self.TireModel:SetSkin( v:GetSkin(i) )
        self.TowerModel:SetSkin( v:GetSkin(i) )
        self.PipeModel:SetSkin( v:GetSkin(i) )
    end
end

I’ll be honest I have no idea what the fuck I’m doing.

Does anyone have a snippet of code that does what I can’t figure out by myself?

Try ENT:SkinChanger()



function ENT:ChangeSkin( i )
  self.TireModel:SetSkin( i )
  self.TowerModel:SetSkin( i )
  self.PipeModel:SetSkin( i )
  self:SetSkin( i )
end

Usage:



e:ChangeSkin( 3 )