Attempt to index number with UpdateAsync

This is literally the most basic use of UpdateAsync isn’t it? Why does it say attempt to index >number< with UpdateAsync?

Some change I’m not aware of?

function GiveTickets(Player, Tickets)
	local PlayerId = Player.UserId
	local success, err = pcall(function()
		if DataStore:GetRequestBudgetForRequestType(Enum.DataStoreRequestType.UpdateAsync) < 2 then
			repeat wait(1) warn("Hit UpdateAsync data limit - retrying (+tickets)") until DataStore:GetRequestBudgetForRequestType(Enum.DataStoreRequestType.UpdateAsync) >= 2
		end	
		Tickets:UpdateAsync(Player.UserId.."_Tickets", function(old)
			local new = old or 0
			
			new = new + 1
			spawn(function()
				Events.Notification:FireClient(Player, "You got a ticket! Check out the Blacksmith at spawn.", "Veles")
				Events.OwnsAsset:FireClient(Player, "Tickets", new)
				Events.ShopEvent:FireClient(Player, "TICKET")
			end)
			return new
		end)
	end)
	print(err)
	print(success)
	return success
end

It means you’re doing someNumber:UpdateAsync(), so in this case probably tickets. I don’t know what Tickets is since that bit of code isn’t shown, but I’d wager it’s a number. Possibly if you have Tickets declared at the top of the script to be a DataStore, you might not have realized that by putting a variable called Tickets as a function argument you are effectively overwriting it for the duration of the function.

oh my gosh I’m dumb I named the datastore after the value

thank u.

1 Like

honestly surprised it took this long and your help for me to figure that out. i must be somewhere else

Tickets:UpdateAsync(Player.UserId.."_Tickets", function(old)
Here you’re calling “UpdateAsync()” through a variable named “Tickets” which holds an integer type value, instead you need to call “UpdateAsync()” through the created “DataStore” instance which was returned from a previous “GetDataStore()” or “GetOrderedDataStore()” call.