DLabel problem

I have a little ticket system for an addon and ive got problems updating the amount of tickets i have (vgui wise) for instance when I buy a new ticket i have to re-open the menu for it to show “tickets: 1”

Heres the ticket code:


 

local meta = FindMetaTable("Player")

function meta:GetTickets()

	return self:GetNWInt("Tickets")

end

function meta:GiveTickets(amount)

	local curTicks = self:GetNWInt("Tickets")
	self:SetNWInt("Tickets", curTicks + amount )

end

function meta:TakeTickets(amount)
	
	local curTicks = self:GetNWInt("Tickets")
	self:SetNWInt("Tickets", curTicks - amount)

end

function meta:SetTickets(amount)

	self:SetNWInt("Tickets", amount)

end





Heres the DLabel drawing the amount:



local tickets = LocalPlayer():GetTickets()
local Tickets = vgui.Create("DLabel", LuckFrame)
		Tickets:SetPos(10, 80)
		//Tickets:SetText( "Tickets: "..tickets )
		Tickets.Think = function() Tickets:SetText("Tickets: "..tickets) Tickets:SizeToContents() end
		Tickets:SetTextColor(Color(255,255,255))



It worked when I used think for the pointshop points but not this system. Anyway i can fix this thanks?

Bump. Still can’t figure out how to fix this, if anyone could skim through the code and figure why it’s not updating it would be a huge help!
(Since I’m on my phone I’ll have to post the github link)

If I buy a ticket, instead of the DLabel text showing “Tickets: 1” It shows “Tickets: 0” and I have to re-open the menu for the DLabel to update to “Tickets: 1”

Change up your derma variable names a bit more, I’m looking at like 3 different uses of the word ‘tickets’ :stuck_out_tongue:

You are using the think hook correctly to constantly set the text to ‘tickets’, but your problem is that you only declare ‘tickets’ once. So just move ‘tickets = LocalPlayer():GetTickets()’ right above your ‘SetText()’ function so that it automatically updates both your variable and text!

Ah thanks I just used:


 Tickets.Think = function() Tickets:SetText("Tickets: "..LocalPlayer():GetTickets()) Tickets:SizeToContents() end