button.OnCursorEntered = function() | Help


Im currently on a lua project. Since Im new to LUA coding, I have my problems.

Currently, I set up a nice derma that pops up on the players spawn to choose the job to play with.

In the button.OnCursorEntered = function() I want to put a function, that it shows the player model on the right side, BUT ONLY if my mouse is on the button. Now, the problem nr 1. I have is, that when I exit the button with my crusor, the model still shows. And If I put my crusor on a different button with the same function, the model adds on top of the existing one. Which is pretty annoying.

I set this up so far:

			local button = vgui.Create( 'DButton' )
			button:SetParent( base )
			button:SetPos( ScrW()/25 + 160, ScrH()/25 + 320 )
			button:SetSize( 100, 20 )
			button:SetText( 'Governor' )
			function button:Paint( w, h )
				draw.RoundedBox( 0, 0, 0, w, h, Color(222, 222, 222, 120 ) )
			local In = false
			button.OnCursorEntered = function()
				In = true
				local icon = vgui.Create( "DModelPanel", f )
				icon:SetParent( base )
				icon:SetPos( ScrW()/25 + 500, ScrH()/25 + 50 )
				icon:SetSize( 700, 700 )
				icon:SetModel( LocalPlayer():GetModel() )
			button.OnCursorExited = function()
				In = false
			function button:Paint( w, h )
				if In then
				surface.SetDrawColor(222, 222, 222, 60 )
				surface.DrawRect(0, 0, button:GetWide(), button:GetTall())
			function button:DoClick()

  1. How can I make the model disappear when I exit the button. 2) I want a little text on the right as description. How do I make it disappear when I exit the button

And nother question:

How do I make the VGUI disappear, when I have SELECTED a job/button. (I have a job that spawns a med kit in front of you. Now if you just click the job 100 times, 100 med kits appear. Its highly abusable. I want the derma to disappear, so you need to die, before changing to another job again)

THANK YOU SO MUCH for reading this thread!

If you could give me a link to some website (wiki.garrysmod.com) where I can look up all the functions I need, it would help me aswell. I do not expect you to go over the entire code and correct it for me. Of course that would be amazing, but its (I suppose) hard work. I just need a ‘little’ help and im good to go.


-Please don’t be too harsh with me, :p. I started lua coding yesterday-

[editline]18th May 2014[/editline]

Nobody has an idea how to help me? Or at least send me a link? :open_mouth:

Maybe DModelPanel:Clear() or Remove() ?