local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local PurchaseHistory = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
function onPlayerPurchased (player)
game:GetService("StarterGui"):SetCore("ChatMakeSystemMessage",{
Text = ".. player.Name .. " has bought "receiptInfo.PlayerId .. ":" .. receiptInfo.PurchaseId.
if PurchaseHistory:GetAsync(playerProductKey) then
return Enum.ProductPurchaseDecision.PurchaseGranted
end
Color = Color3.new(255,255,255);
Font = Enum.Font.SourceSansBold;
FontSize = Enum.FontSize.Size18;
})
end
local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
PurchaseHistory:SetAsync(playerProductKey, true)
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
As a Local script in StarterGUI.

3 comments
You can't use DataStores in local scripts
Please properly indent your code. Properly indented code is easier to read and debug.
Also as the comment above stated: You cannot access the DataStoreService from the client or more specifically, a LocalScript.