After Zmaster's edits these are the things you need to correct.
Remove the "local" in line 7
Zmaster's correction for line 10 is incorrect, the code on line 11 needs to be on line 10
MyDerma:SetPos( midW - ( MyDerma:GetWide() / 2 ), midH - (MyDerma:GetTall() / 2) )
You also have a nil value "midW" on line 10 and probably should be "midx" instead
MyDerma:SetPos( midx - ( MyDerma:GetWide() / 2 ), midH - (MyDerma:GetTall() / 2) )
Like Zmaster said, line 14 should be
local MyLabel = vgui.Create( "DLabel", MyDerma )
There was a ":" on line 18 that isn't supposed to be there.
MyButton:SetText( "Click to die" )
The corrected script should be
if (SERVER) then
end
if (CLIENT) then
local midx, midH = ScrW() / 2, ScrH() / 2
function OpenMyDerma()
local MyDerma = vgui.Create( "DFrame" )
MyDerma:SetSize(250, 250)
MyDerma:SetPos( midx - ( MyDerma:GetWide() / 2 ), midH - (MyDerma:GetTall() / 2) )
MyDerma:SetTitle( "Best Derma EVER" )
local MyLabel = vgui.Create( "DLabel", MyDerma )
MyLabel:SetPos( 175, 20 )
MyLabel:SetText( "This is my awesome label" )
local MyButton = vgui.Create( "DButton", MyDerma )
MyButton:SetText( "Click to die" )
MyButton:SetPos( 90, 60 )
MyButton.DoClick = function()
RunConsoleCommand( "kill" )
end
end
concommand.Add( "openmyderma", OpenMyDerma )
end
Now that your code is able to be ran there are some things that need to be added in order for the GUI to be used.
Add this below line 11
MyDerma:SetVisible( true )
MyDerma:MakePopup()
Without that you can't click the button you have.
The final code should be
if (SERVER) then
end
if (CLIENT) then
local midx, midH = ScrW() / 2, ScrH() / 2
function OpenMyDerma()
local MyDerma = vgui.Create( "DFrame" )
MyDerma:SetSize(250, 250)
MyDerma:SetPos( midx - ( MyDerma:GetWide() / 2 ), midH - (MyDerma:GetTall() / 2) )
MyDerma:SetTitle( "Best Derma EVER" )
MyDerma:SetVisible( true )
MyDerma:MakePopup()
local MyLabel = vgui.Create( "DLabel", MyDerma )
MyLabel:SetPos( 175, 20 )
MyLabel:SetText( "This is my awesome label" )
local MyButton = vgui.Create( "DButton", MyDerma )
MyButton:SetText( "Click to die" )
MyButton:SetPos( 90, 60 )
MyButton.DoClick = function()
RunConsoleCommand( "kill" )
end
end
concommand.Add( "openmyderma", OpenMyDerma )
end