Dictionaries are stored as key-value pairs and donât have numerical indices, so DataTable[1] doesnât exist even if the table contains something. Dictionaries arenât ordered either. You could do DataTable["1"] if you manually enter a key-value pair with its key being [â1â] (a string)
For your application it looks like you want to do Cash.Value = DataTable.Cash or 0
What is returned by the pcall where youâre assigning DataTable = LeaderstatsTable:GetAsync(player.UserId)?
If that call fails, what does DataTable become after DataTable = DefaultDataTable?
It may no longer be a referenceable dictionary
function PlayerLeft(Player)
local success,err = pcall(function()
LeaderstatsTable:SetAsync(Player.UserId,DataTable)
end)
if success then
print("Success.. Thanks for playing")
else
warn("Error!",err)
end
end```
Can you print(DataTable) just prior to where your Cash.Value = [...] code is? It seems DataTable is being overwritten from a dictionary to a number somewhere
Alright, so itâs overwritten. Try adding debug statements to print DataTable whenever its changed or referenced to see where itâs being altered. Places like as you call SetAsync, when you call GetAsync, when you compared DataTable == {} [...], and where you call DataTable.Cash.