Label not attached to frame

Hello,

I have a problem with my Lua code : Label is not “connected” to my frame.

Here’s my frame :

[lua]
local TaxiPanel = vgui.Create( “DFrame” )
TaxiPanel:SetSize( 800, 400 )
TaxiPanel:Center()
TaxiPanel:SetTitle( “Window” )
TaxiPanel:MakePopup()
TaxiPanel:ShowCloseButton( true )
TaxiPanel:SetDraggable( false )
TaxiPanel:SetVisible( true )
[/lua]

Here’s my button :
[lua]
local button = vgui.Create(“DButton” , TaxiPanel)
button:SetPos(590,85)
button:SetSize(200,45)
button:SetText(“Centre Ville”)
button.DoClick = centreVille
[/lua]

Here’s my function :
[lua]
function centreVille()
print(“TP Centre Ville”)
centreVillePresentation = true

if centreVillePresentation == true then

local label = vgui.Create("DLabel" , TaxiPanel)
label:SetPos( 400, 200 )
label:SetText( "CENTRE VILLE" )

else
end

end
[/lua]

Screenshot of what it does for me :

http://image.noelshack.com/fichiers/2016/04/1454013922-0145-noelpush.jpeg

Screenshot of what it does for other :

http://image.noelshack.com/fichiers/2016/04/1454015680-6404-noelpush.png

If someone could help me. :slight_smile:
Thanks.



local TaxiPanel = vgui.Create( "DFrame" )
TaxiPanel:SetSize( 800, 400 )
TaxiPanel:Center()
TaxiPanel:SetTitle( "Window" )
TaxiPanel:MakePopup()
TaxiPanel:ShowCloseButton( true )
TaxiPanel:SetDraggable( false )
TaxiPanel:SetVisible( true )

function centreVille()
  
  centreVillePresentation = true

    if (centreVillePresentation) then

        print("TP Centre Ville")

        local label = vgui.Create("DLabel" , TaxiPanel)
        label:SetPos( 400, 200 )
        label:SetText( "CENTRE VILLE" )
        label:SizeToContents()
        
    end

end

local button = vgui.Create("DButton" , TaxiPanel)
button:SetPos(590,85)
button:SetSize(200,45)
button:SetText("Centre Ville")
button.DoClick = centreVille


By having a fast look, then it seems like that you’re parenting everything right.
If the structure of the code is as posted, then i think that it is better to define the centreVille function before defining it in button.DoClick (As shown in my post). Also just for safety reasons, make sure that you run the code clientside. https://wiki.garrysmod.com/page/Beginner_Tutorial_Intro

Youre trying to use the variable TaxiPanel in a function that youve defined outside the function that creates that vatiable, so youre making it so that it tries to parent it to a nil value beacouse the TaxiPanel variable is not defined there.