How can I add "Collect!" button on my bitcoin miner?

Hey, I have been trying to code a bit miner entity. It is automatically adding bits to its networked int. But my problem is with creating a collect button, I have no idea how can I create one.

Here is the init.lua



AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")

include("shared.lua")

util.AddNetworkString("bithud")
util.AddNetworkString("receive")

function ENT:Initialize()
	self:SetModel("models/props_lab/servers.mdl")
	self.Entity:SetUseType(SIMPLE_USE)
	self:PhysicsInit(SOLID_VPHYSICS)
	self:SetMoveType(MOVETYPE_VPHYSICS)
	self:SetSolid(SOLID_VPHYSICS)

	local phys = self:GetPhysicsObject()

	if phys:IsValid() then
		phys:Wake()


	end


end




function ENT:Use(activator)
	local myBits = tonumber( self:GetNWInt("bits") )
	local myMoney = tonumber( activator:GetNWInt("money") )
	local myBitMoney = myBits*100

	net.Start("bithud")
	net.Send(activator)
end




function ENT:Think()
	local myBits = tonumber( self:GetNWInt("bits") )
	self:SetNWInt("bits", myBits + 1 )

	self:NextThink(CurTime() + 3)
	return true
end




and the cl_init.lua


include("shared.lua")

function ENT:Draw()
	self:DrawModel()
end

function bithud()


	local bitmenu = vgui.Create("DFrame")
 	bitmenu:SetTitle("Bitminer Menu")
 	bitmenu:SetSize(250,190)
 	bitmenu:SetPos(ScrW()/2-125, ScrH()/2-95)
 	bitmenu:SetDraggable(true)
 	bitmenu:ShowCloseButton(true)
 	bitmenu:MakePopup()
 	bitmenu.Paint = function()


 	local client = LocalPlayer()
	local eye = client:GetEyeTrace()


	if eye.Entity:GetClass() == "bitminer" then


		surface.CreateFont("BitFont",{font = Tahoma, size = 25, })
		draw.RoundedBox(2,0,0,ScrW(),ScrH(),Color(70,70,70,200))
 		draw.SimpleText(eye.Entity:GetNetworkedInt("bits").. " bitcoins mined.","BitFont",37,35,Color(255,255,255,255))
 		


 			local bcol = vgui.Create("DButton", bitmenu)
 			 bcol:SetSize(110,40)
 			 bcol:SetText("Collect")
 			 bcol:SetPos(50,90)
 			 
 			 function bcol:DoClick()
 			 	local ply = LocalPlayer()
 			 	net.Start("receive")
 			 	net.SendToServer(ply)
 		end
	end
end
end

net.Receive("bithud", bithud)


Don’t mind the “if eye.Entity:GetClass() == “bitminer” then” part, I have been trying things, I know it’s not necessary.

Thanks!

your way is right, but there is a simple mistake which is you are trying to create vgui button in a PAINT function of a DFrame.

heres how your cl_init should look like;


include("shared.lua")

function ENT:Draw()
	self:DrawModel()
end

local function bithud()
	local bitmenu = vgui.Create("DFrame")
 	bitmenu:SetTitle("Bitminer Menu")
 	bitmenu:SetSize(250,190)
 	bitmenu:SetPos(ScrW()/2-125, ScrH()/2-95)
 	bitmenu:SetDraggable(true)
 	bitmenu:ShowCloseButton(true)
 	bitmenu:MakePopup()
 	bitmenu.Paint = function()
 		-- PAINT STUFF HERE
 	end

 	local collbutton = vgui.Create("DButton",bitmenu)
 	collbutton:Dock(TOP) -- I dont want to mess with setsize/setpos. You can delete this
 	collbutton:SetText("")
 	collbutton.Paint = function()
 		-- PAINT BUTTON HERE
 	end
 	collbutton.DoClick = function()
 		net.Start("receive")
 		net.SendToServer()
 	end
end
net.Receive("bithud", bithud)

and add this to init.lua;


net.Receive("receive", function(len, ply)
	local eye = ply:GetEyeTrace()

	if eye.Entity:GetClass() == "bitminer" then
		-- DO SOME CHECKS
			if eye.Entity:GetPos():Distance(ply:GetPos())>100 then return end -- if the player is far away from that ent
			if eye.Entity:GetNWInt("money")<=0 then return end -- if the ent doesnt have any money
		--END CHECKS

		-- ADD MONEY TO PLAYER
			-- I guess you are using darkrp so..

			local money = eye.Entity:GetNWInt("bits")*100 -- I multiplied with 100 because you did.
			ply:addMoney(money)

			-- You may want to inform player about it.
			DarkRP.notify(ply, 0, 4, "You have collected " ..money.. "$ from bitminer.")
		--END
	end
end)

Thank you very much!
Problem solved.