Problem with removing DModelPanel

Hey guys, I have a small problem with my DModelPanel. I have it so it creates a DModelPanel on InitPostEntity, then starts a timer that goes off every 1 second forever to see if the player’s model has changed. However, I have a small problem. Whenever the timer goes off, it compares the LocalPlayer’s player model with the DModelPanel’s model, and if there different, it removes the old DModelPanel and creates a new DModelPanel using the LocalPlayer’s player model, but it says this error on line 25: Attempt to index ‘GetModel’ a nil value. I know that it knows what the LocalPlayer’s player model is, but it can’t seem to find the DModelPanel’s model. Any help?

[lua]
local ply = LocalPlayer()

hook.Add(“InitPostEntity”, “DrawPlayerModel”, function()
Avatar = vgui.Create(“DModelPanel”)
Avatar:SetModel(ply:GetModel())
Avatar:SetCamPos(Vector( 14, 4, 65))
Avatar:SetLookAt(Vector( 0, 0, 66.5 ))
Avatar:SetSize(150, 150)
Avatar:SetPos(ScrW() * 0.08, ScrH() * 0.7)
Avatar.PaintOver = function()
surface.SetDrawColor(0, 0, 0, 215)
surface.DrawRect(0, 0, Avatar:GetWide(), 50)

	surface.SetTextColor(255, 255, 255, 230)
	surface.SetFont("Trebuchet20")

	local w, h = surface.GetTextSize("Placeholder")

	surface.SetTextPos(Avatar:GetWide() / 2 - w / 2, 50 / 2 - h / 2)
	surface.DrawText("Placeholder")
end
function Avatar:LayoutEntity(Entity) return end

	timer.Create("RefreshAvatar", 1, 0, function()
		if ( ply:GetModel() ~= Avatar:GetModel() ) then
			Avatar:Remove()

			Avatar = vgui.Create("DModelPanel")
			Avatar:SetModel(ply:GetModel())
			Avatar:SetCamPos(Vector( 14, 4, 65))
			Avatar:SetLookAt(Vector( 0, 0, 66.5 ))
			Avatar:SetSize(150, 150)
			Avatar:SetPos(ScrW() * 0.08, ScrH() * 0.7)
			Avatar.PaintOver = function()
				surface.SetDrawColor(0, 0, 0, 215)
				surface.DrawRect(0, 0, Avatar:GetWide(), 50)

				surface.SetTextColor(255, 255, 255, 230)
				surface.SetFont("Trebuchet20")

				local w, h = surface.GetTextSize("Placeholder")

				surface.SetTextPos(Avatar:GetWide() / 2 - w / 2, 50 / 2 - h / 2)
				surface.DrawText("Placeholder")
			end
			function Avatar:LayoutEntity(Entity) return end
		end
	end)

end)
[/lua]

Quick look here: http://glua.me/bin/?path=/lua/vgui/dmodelpanel.lua tells me that you need Avatar.Entity:GetModel()

I’ll try that. Give me one second.

[editline]fixed[/editline]

Thanks man!