Data store is not working

Hi, I have an issue with my data store and it prints yes for success and prints data saving however it does not show when I rejoin. I had a touch brick which gave me 10 Molla however when I rejoined, I had no Molla.

local myDatasStore = datastore:GetDataStore("myDataStore")-- In Quotes is name of data store

	local leaderstats ="Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = p
	local money ="IntValue")
	money.Name = "Molla"
	money.Parent = leaderstats
	local playerid = "Player_"..p.UserId
	myDatasStore:GetAsync(playerid) -- Get data
	--Load Data
	local Data = nil
	local success, errormessage = pcall(function()
		Data =  myDatasStore:GetAsync(playerid)---- Local for it to be shown for both functions
		return Data
	if success then -- if the data is found
		p.leaderstats.Molla.Value = Data
		-- where data is loaded into the actual game

	local playerid = "Player_"..p.UserId
	local Data = p.leaderstats.Molla.Value --- Turning it into data
	local success, errormessage = pcall(function()
		myDatasStore:GetAsync(playerid, Data)-- saving the money -- Get the data already in game to save
	if success then
		print("Data saved")

Howdy, how are you doing?
Are you sure you have this setting ON?

Yes I do have the setting on, is there any others I need ?

You’re not actually calling any methods on your datastore to save your information, only the GetAsync method which retrieves previously saved data. Please take a look at the following datastore methods to get a better idea of how you want to go about saving your game’s data

GlobalDataStore:SetAsync (
GlobalDataStore:UpdateAsync (

My advice would be to use UpdateAsync upon the Player’s removal.

This is the problem, you’re loading the data wrong.

Why are you loading the data twice? Load it once, so remove the first GetAsync() function code line.

The second is your pcall function. Since you have a variable to store the data, you don’t have to return the Data.

If that still doesn’t work, then you’re saving the data wrong.

This seems to be the error in this case then, you’re getting the async, not setting it.

change the “GetAsync” with “SetAsync”

This worked, thank you lots ////

No problem, though be sure to read the API too next time like @mew903 mentioned above with the links too. You could’ve solved this issue with a bit of searching.

This is not exactly a fix to the issue, but I thought it was good to note something:

You are creating a local variable Data and then setting it within the pcall function.
While this works, it is not advised to do it this way.
The pcall function actually sets what you have as errormessage to what you return within the pcall function.
You should make this code

local success, data = pcall(function()
	Data =  myDatasStore:GetAsync(playerid)---- Local for it to be shown for both functions
	return Data

then data is either the save data or the error message
if success is true then data is equal to the save data
if success is false then data is equal to the error message.