local productFunctions = {}
productFunctions[1906083017] = function(receipt, player)
local leaderstats = player:FindFirstChild("leaderstats")
local coins = leaderstats and leaderstats:FindFirstChild("Coins")
if coins then
coins.Value += 300
return true
end
end
local function processReceipt(receiptInfo)
local userId = receiptInfo.PlayerId
local productId = receiptInfo.ProductId
local player = Players:GetPlayerByUserId(userId)
if player then
local handler = productFunctions[productId]
local success, result = pcall(handler, receiptInfo, player)
if success then
return Enum.ProductPurchaseDecision.PurchaseGranted
else
warn("Failed to process receipt:", receiptInfo, result)
end
end
return Enum.ProductPurchaseDecision.NotProcessedYet
end
MarketplaceService.ProcessReceipt = processReceipt
```local script
```local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local productId = 1906083017
local function promptPurchase()
MarketplaceService:PromptProductPurchase(player, productId)
end
script.Parent.MouseButton1Click:Connect(promptPurchase)
You are using a local script, and process receipt can only be done once by a server script. The only thing you should have on the local script is the prompt purchase, so just move the process receipt to the server and you should be good.
productFunctions[1906083017] = function(receipt, player)
local leaderstats = player:FindFirstChild("leaderstats")
local coins = leaderstats:FindFirstChild("Coins")
if coins then
print(coins)
coins.Value += 300
return true
end
end
put the print before the if statement since nothing is being printed it means that it didnt find coins in leaderstats make sure that everything is named correctly
productFunctions[1906083017] = function(receipt, player)
local leaderstats = player:FindFirstChild("leaderstats")
local coins = leaderstats:FindFirstChild("Coins")
print(coins)
if coins then
coins.Value += 300
return true
end
end
local DataStoreService = game:GetService("DataStoreService")
local playerDataStore = DataStoreService:GetDataStore("PlayerData")
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local COINS_PER_MINUTE = 100
local BONUS_COINS_GAMEPASS = 1000
local GAMEPASS_ID = 885153406
local function loadPlayerData(player)
local playerKey = "Player_" .. player.UserId
local defaultData = {
Coins = 0,
TimePlayed = 0,
}
local success, playerData = pcall(function()
return playerDataStore:GetAsync(playerKey)
end)
if success and playerData then
return playerData
else
return defaultData
end
end
local function savePlayerData(player, playerData)
local playerKey = "Player_" .. player.UserId
local success, err = pcall(function()
playerDataStore:SetAsync(playerKey, playerData)
end)
if not success then
warn("Failed to save data for " .. player.Name .. ": " .. tostring(err))
end
end
local function onPlayerAdded(player)
local playerData = loadPlayerData(player)
local ownsGamePass = false
local success, err = pcall(function()
ownsGamePass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, tostring(GAMEPASS_ID))
end)
if success and ownsGamePass then
playerData.Coins = playerData.Coins + BONUS_COINS_GAMEPASS
savePlayerData(player, playerData) -- Save immediately after adding bonus coins
end
-- Create leaderstats
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
-- Coins
local coins = Instance.new("IntValue")
coins.Name = "Coins"
coins.Value = playerData.Coins
coins.Parent = leaderstats
-- Time Played
local timePlayed = Instance.new("IntValue")
timePlayed.Name = "TimePlayed"
timePlayed.Value = playerData.TimePlayed
timePlayed.Parent = leaderstats
local function giveCoinsAndUpdateTime()
while true do
local bonusCoins = 0
-- Check if player owns the game pass
local success, ownsGamePass = pcall(function()
return MarketplaceService:UserOwnsGamePassAsync(player.UserId, tostring(GAMEPASS_ID))
end)
if success and ownsGamePass then
bonusCoins = BONUS_COINS_GAMEPASS
end
if not ownsGamePass then
print("not")
end
playerData.Coins = playerData.Coins + COINS_PER_MINUTE + bonusCoins
coins.Value = playerData.Coins
playerData.TimePlayed = playerData.TimePlayed + 1
timePlayed.Value = playerData.TimePlayed
savePlayerData(player, playerData)
wait(60) -- Wait for 60 seconds (1 minute)
end
end
spawn(giveCoinsAndUpdateTime)
end
local productFunctions = {}
productFunctions[1906083017] = function(receipt, player)
local leaderstats = player:FindFirstChild("leaderstats")
local coins = leaderstats:FindFirstChild("Coins")
if coins then
coins.Value += 300
return true
end
end
local function processReceipt(receiptInfo)
local userId = receiptInfo.PlayerId
local productId = receiptInfo.ProductId
local player = Players:GetPlayerByUserId(userId)
if player then
local handler = productFunctions[productId]
local success, result = pcall(handler, receiptInfo, player)
if success then
return Enum.ProductPurchaseDecision.PurchaseGranted
else
warn("Failed to process receipt:", receiptInfo, result)
end
end
return Enum.ProductPurchaseDecision.NotProcessedYet
end
MarketplaceService.ProcessReceipt = processReceipt
local function onPlayerRemoving(player)
local playerData = {
Coins = player.leaderstats.Coins.Value,
TimePlayed = player.leaderstats.TimePlayed.Value,
}
savePlayerData(player, playerData)
end
-- Connect events
game.Players.PlayerAdded:Connect(onPlayerAdded)
game.Players.PlayerRemoving:Connect(onPlayerRemoving)
ocal function processReceipt(receiptInfo)
local userId = receiptInfo.PlayerId
local productId = receiptInfo.ProductId
local player = Players:GetPlayerByUserId(userId)
if player then
local handler = productFunctions[productId]
local success, result = pcall(handler, receiptInfo, player)
if success then
print("Success")
return Enum.ProductPurchaseDecision.PurchaseGranted
else
warn("Failed to process receipt:", receiptInfo, result)
end
end
return Enum.ProductPurchaseDecision.NotProcessedYet
end
If it is an IntValue OR a NumberValue, do what they says. If its an integer and NOT a value (which can’t be displayed on the leaderboard), then you don’t have to, but you most likely still have to do what they said.
local function processReceipt(receiptInfo)
print("Success")
local userId = receiptInfo.PlayerId
local productId = receiptInfo.ProductId
local player = Players:GetPlayerByUserId(userId)
if player then
local handler = productFunctions[productId]
local success, result = pcall(handler, receiptInfo, player)
if success then
return Enum.ProductPurchaseDecision.PurchaseGranted
else
warn("Failed to process receipt:", receiptInfo, result)
end
end
return Enum.ProductPurchaseDecision.NotProcessedYet
end