-- SERVER SIDE SCRIPT --
local MarketplaceService = game:GetService("MarketplaceService")
local DataStoreService = game:GetService("DataStoreService")
local ServerStorage = game:GetService("ServerStorage")
local PreviousPurchases = DataStoreService:GetDataStore("PreviousPurchases1")
MarketplaceService.ProcessReceipt = function(receipt)
local ID = receipt.PlayerId.."-"..receipt.PurchaseId
local success = nil
pcall(function()
success = PreviousPurchases:GetAsync(ID)
end)
if success then -- Has it already been bought ?
-- Purchase has already been done
return Enum.ProductPurchaseDecision.PurchaseGranted
end
local player = game.Players:GetPlayerByUserId(receipt.PlayerId)
if not player then
-- Left, disconnected
return Enum.ProductPurchaseDecision.NotProcessedYet -- We're going to give their rewards next time they join / next time fired
else
if receipt.ProductId == IDHere then
player.leaderstats.Points.Value + 2000
end
pcall(function()
PreviousPurchases:SetAsync(ID,true)
end)
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
-- LOCAL SCRIPT --
local MarketplaceService = game:GetService("MarketplaceService")
script.Parent.MouseButton1Click:Connect(function()
MarketplaceService:PromptProductPurchase(Player, IDHere)
end)