I have run into a snafoo

Is there a way to get the users name in the BuildCPanel function?

function TOOL.BuildCPanel(Panel)

Ive tried LocalPlayer, ive tried self:GetOwner, ive even tried tool:GetOwner. I don’t know what im doing, i cant find any way.

Ive even created a variable outside of it, but for some reason its value is nil when its in BuildCpanel, but not nil when I do this

function TOOL:Think()
PlayerName = self:GetOwner():GetName()

Try defining
[lua]local playername = LocalPlayer():Nick()[/lua]
outside of the CPanel function and then use it inside?

Works just fine for me.

[lua]function TOOL.BuildCPanel( panel )
panel:AddControl(“Header”, { Text = “Testing”, Description = “Testing getting nick” })

panel:AddControl( "Label", { Text = "Name: "..LocalPlayer():Nick() }  )


Can you post the error and the code?


Its all good, i used a different method for what I was doing.

how would that do anything…

BuildCPanel is called without a reference to the tool and likely when the spawn menu is created. This isn’t possible in a direct manner - you’d need to create your own vgui control and add it to the panel, and then update that control based on the player.