so i got this script in serverscriptservice
local DataStoreService = game:GetService("DataStoreService")
local LeaderstatDataStore = DataStoreService:GetDataStore("LeaderstatDataStore")
local DeveloperProductID = script.id.Value
game.Players.PlayerAdded:Connect(function(player)
local Leaderstat = player.leaderstats.Cash
local LeaderstatKey = player.UserId .. "Cash"
local success, savedValue = pcall(function()
return LeaderstatDataStore:GetAsync(LeaderstatKey)
end)
if success and savedValue then
Leaderstat.Value = savedValue
end
local PurchasedFlagKey = player.UserId .. "_Purchased"
local purchasedSuccess, purchasedValue = pcall(function()
return LeaderstatDataStore:GetAsync(PurchasedFlagKey)
end)
if not purchasedSuccess or purchasedValue == nil then
purchasedValue = false
end
if not purchasedValue then
game:GetService("MarketplaceService").ProcessReceipt = function(receiptInfo)
if receiptInfo.PlayerId == player.UserId and receiptInfo.ProductId == DeveloperProductID then
Leaderstat.Value = Leaderstat.Value + script.Cash.Value
local purchaseSuccess, purchaseError = pcall(function()
LeaderstatDataStore:SetAsync(PurchasedFlagKey, true)
end)
if not purchaseSuccess then
warn("Failed to save purchase data:", purchaseError)
end
local saveSuccess, saveError = pcall(function()
LeaderstatDataStore:SetAsync(LeaderstatKey, Leaderstat.Value)
end)
if not saveSuccess then
warn("Failed to save Cash data:", saveError)
end
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
end)
heres the GUI script:
local button = script.Parent
local player = game.Players.LocalPlayer
local gamePassId = script.Parent.GamepassId
button.MouseButton1Click:connect(function()
if player then
game:GetService("MarketplaceService"):PromptProductPurchase(player, gamePassId.Value)
end
end)
and the gui prompt works fine but the server script doesnt give cash once bought the dev product + it gives no error at all