Issues with dmodelpanels

Hello!

I’m currently having a small issue while using DModelPanels.

The problem is when the menu appears my frame rate starts to drop from 300 to around 10 fps.
I’m not quite sure what the issue is. I can only think that somehow the menu is constantly getting refreshed.

Any help is appreciated!

My clientside file:

[lua]
function StatsMenu()
local StatsMenu = vgui.Create(“DFrame”)
StatsMenu:SetSize(500, 700)
StatsMenu:Center()
StatsMenu:SetTitle( “” )
StatsMenu:ShowCloseButton( true )
StatsMenu:SetDraggable( true )
StatsMenu.Paint = function()
surface.SetDrawColor( 0, 128, 200, 230 )
surface.DrawRect( 0, 0, 500, 25)
surface.SetDrawColor( 81, 81, 81, 150 )
surface.DrawRect( 0, 0, StatsMenu:GetWide(), StatsMenu:GetTall() )
surface.SetDrawColor( 50, 50, 50, 50 )
surface.DrawOutlinedRect( 0, 0, StatsMenu:GetWide(), StatsMenu:GetTall() )

local icon = vgui.Create( “DModelPanel”, panel )
icon:SetModel( LocalPlayer():GetModel() )
icon:SetSize( 200, 200 )
icon:SetParent(StatsMenu)
icon:SetCamPos( Vector( 50, 50, 120 ) )
icon:SetLookAt( Vector( 0, 0, 0 ) )
end
StatsMenu:SetVisible( true )
end
concommand.Add(“statsopen”, StatsMenu)
[/lua]

You are creating the model panel every 0.01 seconds.

How do I prevent this?

Don’t create the panel in a paint hook.

Hehehe, alright time for some spoon feeding before bed I guess:

[lua]
function StatsMenu()
local StatsMenu = vgui.Create(“DFrame”)
StatsMenu:SetSize(500, 700)
StatsMenu:Center()
StatsMenu:SetTitle( “” )
StatsMenu:ShowCloseButton( true )
StatsMenu:SetDraggable( true )
StatsMenu.Paint = function()
surface.SetDrawColor( 0, 128, 200, 230 )
surface.DrawRect( 0, 0, 500, 25)
surface.SetDrawColor( 81, 81, 81, 150 )
surface.DrawRect( 0, 0, StatsMenu:GetWide(), StatsMenu:GetTall() )
surface.SetDrawColor( 50, 50, 50, 50 )
surface.DrawOutlinedRect( 0, 0, StatsMenu:GetWide(), StatsMenu:GetTall() )
end

local icon = vgui.Create( “DModelPanel”, StatsMenu )
icon:SetModel( LocalPlayer():GetModel() )
icon:SetSize( 200, 200 )
icon:SetCamPos( Vector( 50, 50, 120 ) )
icon:SetLookAt( Vector( 0, 0, 0 ) )

StatsMenu:SetVisible( true )
end
concommand.Add(“statsopen”, StatsMenu)
[/lua]

Thanks!