Data Isn't Saving Even with API Services On And Datastore Leaderstats

Data Isn’t Saving Even with API Services On And Datastore Leaderstats.
API Is On And This Is The Coins Handler.
There is a buy coin gamepass but when you leave the game and re-join it doesn’t work.
What do i do ? Below Me Is The Coins Handler.

local mps = game:GetService(“MarketplaceService”)

local coinsProductIDs =
{
[1096714714] = 100,
[1096715119] = 500,
[1096715447] = 1000,
[1096715703] = 5000,
}

game.Players.PlayerAdded:Connect(function(plr)

local ls = Instance.new("Folder")
ls.Name = "leaderstats"
ls.Parent = plr

local coins = Instance.new("IntValue")
coins.Name = "Coins"
coins.Parent = ls

end)

mps.ProcessReceipt = function(purchaseInfo)

local plrPurchased = game.Players:GetPlayerByUserId(purchaseInfo.PlayerId)

if not plrPurchased then
	
	return Enum.ProductPurchaseDecision.NotProcessedYet
end


for productID, coinsGiven in pairs(coinsProductIDs) do
	
	if purchaseInfo.ProductId == productID then
		
		
		plrPurchased.leaderstats.Coins.Value = plrPurchased.leaderstats.Coins.Value + coinsGiven
		
		return Enum.ProductPurchaseDecision.PurchaseGranted
	end
end

end

So I don’t really see a datastore in this script… That might be your problem?

2 Likes

When a player leaves or a server gets shutdown you are supposed to update their data on the actual Datastore not only their in-game values.

1 Like

how do i do that to the datastore ?

oof can you help me or send advice so i can try get this working ?

There are plenty of tutorials related to leaderstats and data saving online. You just have to use the right keywording in Google search engine(for example DataStoreService developer roblox).

1 Like