Hi, i'm making a gamemode for my server. When you press Q the buy menu comes up, it's fine the first time but when you press Q the second time nothing happens. Any help
Code:
[lua]
function GM:BuyMenu(p)
local Money = p:GetNWInt("Money")
if p and p:IsValid() then
frame = vgui.Create( "DFrame" )
frame:Center()
frame:SetSize( 250, 200 )
frame:SetTitle( "Shop" )
frame:SetVisible( true )
frame:SetDraggable( false )
frame:ShowCloseButton( true )
frame:SetDeleteOnClose(true)
frame:SetBackgroundBlur(true)
frame:MakePopup()
p.FrameMadeYet = true
p.frame = frame
p90 = vgui.Create( "DButton", frame )
p90:SetPos( 30, 30 )
p90:SetSize( 100, 50 )
p90:SetText( "P90\n(#500)" )
p90.DoClick = function()
if Money >=500 then
RunConsoleCommand("give_p90")
frame:Close()
end
end
m16 = vgui.Create("DButton",frame)
m16:SetPos(30,85)
m16:SetSize(100,50)
m16:SetText("M16\n(#400)")
m16.DoClick = function(frame)
if Money >=400 then
RunConsoleCommand("give_m16")
end
end
ak47 = vgui.Create("DButton",frame)
ak47:SetPos(135,30)
ak47:SetSize(100,50)
ak47:SetText("AK-47\n(#450)")
ak47.DoClick = function(frame)
if Money >=450 then
RunConsoleCommand("give_ak47")
end
end
end
end
function GM:Think(p)
local p = LocalPlayer()
if input.IsKeyDown(27) and not p.FrameMadeYet then
self:BuyMenu(p)
end
end
[/lua]
p.FrameMadeYet is set to true when the menu is created, but is not set to false when the menu is closed/deleted.
Get rid of the not p.FrameMadeYet stuff and replace it with (!p.frame || !p.frame:IsValid())
or just !IsValid( p.frame)
Sorry, you need to Log In to post a reply to this thread.