[LUA Scripting Issue] Closing derma menu not using a button.

Hello there! I managed to open a menu about the information of a player when you look at him and press E. I would like to know how to close it, when you stop looking at him or when you go too far. I have the Distance value.
Thanks if you awnser.

DermaPanel:Close()

I know that, but I don’t know in what kind of function I have to put this.

[lua]
btn.DoClick = function()
Frame:Close() // If you are using a frame
or
Panel:Remove() // If you are suing a panel
end
[/lua]

But Im not looking to close it with a button, Im looking to close it when you stop looking at the player. Because it’s a menu with the info of the player that you’re looking at.

When you open it said a variable eg. ViewingPly = Entity

[lua]
hook.Add(“Think”,"", function()

local tr = LocalPlayer():GetEyeTrace()

if tr.Entity != ViewingPly or tr.HitWorld then
ViewingPly = nil
Derma:Close()
end
end)
[/lua]

Typing from my phone so that’s general. Don’t forget to put failsafes in.

[lua]
DFrame.Think = function() end
[/lua]

The above is better as it only ‘thinking’ when the menu is open.

I will try it! Many thanks!!!

[editline]12th May 2013[/editline]

Solved, thanks to everyone for trying to help. And thanks to Aide, for giving me the solution :slight_smile: