Why is :GetAsync returning table: (value)?

I am trying to use datastore to make a currency for my game, but I have been having severe difficulty with doing so. I have made a datastore module to create my datastore and set it up for new players, but in my regular script I am trying to make a folder in ReplicatedStorage that basically lists out player info. When the player joins, it creates a folder there under their name and makes a NumberValue with how much money I have, but when I try to return a value using :GetAsync the number remains 0. I tried printing what :GetAsync returns but only get an output similar to table: 0000294888A5D. Here is my script:

                local PlayerStoredData = DataStoreService:GetDataStore("PlayerData")
		local Folder = Instance.new("Folder");
		Folder.Name = plr.Name;
		Folder.Parent = Server.PlayerData
		local moneyValue = Instance.new("NumberValue");
		moneyValue.Name = "Money";
		moneyValue.Parent = Folder;
		local s, m = pcall(function()
		return PlayerStoredData:GetAsync("Player_"..plr.UserId)
		  end)
		if s then
		print(m)	
	end
end
1 Like

Can we see the whole datastore please?

What do you mean by that? I gave my script.

Where do you set the player values?

You don’t need to use a pcall function in this case, because they don’t return custom values other than if it succedeed and the error message (if it failed)

So what you should do is:

if(PlayerStoredData:GetAsync("Player_"..plr.UserId)) then
      -- player had data
end

I’m 90% sure that data stores just store data in a table, even if it’s one value. That’s why it’s returning a table. So you’d have to get the order of data you saved, and make values like “datastorename”[1].

Will need to see the saving code to assist. It’s returning a table because you’re saving a table.


Yes you do, actually. pcall is for protected call, which wraps a function call and catches errors. It allows you to perform your own error handling techniques. Considering DataStores are internally web calls and can have issues with either the API or endpoints, you need to handle those errors to prevent potential data loss or your script terminating due to error.

Caching returns from GetAsync calls is also imperative to functionality. Your suggested “fix” does not do that and instead spends a second call of the budget unnecessarily.


It does not do this.

2 Likes

First off, I strongly recommend you learn how to use the DataStore2 module instead as once you get used to it, it’s way more reliable, it’s a lot easier to use, and the core stuff is already written for you.

If you’re not up for that though, we need to see your SetAsync or UpdateAsync as well, as that is likely where the error is.