|
| 25 Apr 2015 08:43 PM |
I'm trying to add 1000 cash to leaderstats with a devProduct purchase through GUI.
Why doesn't this script in ServerScriptStorage run after they buy the devProduct?
-- local MarketplaceService = game:GetService("MarketplaceService") local ds = game:GetService("DataStoreService"):GetDataStore("Purchases")
local productid = 23489526
MarketplaceService.ProcessReceipt = function(receiptInfo)
for i, p in ipairs(game.Players:GetChildren()) do print("In the start of the script") if player.userId == receiptInfo.PlayerId then print("After user ID")
local h = player.Character:FindFirstChild("Humanoid") local z = game.Players:FindFirstChild(h.Parent.Name)
if receiptInfo.ProductId == productid then print("After comparing IDs") p.leaderstats.Cash.Value = p.leaderstats.Cash.Value + 75
local hint = Instance.new('Message') hint.Text = "Thank you so much for the purchase"..player.Name.."!" hint.Parent = p.PlayerGui wait(3) hint:Destroy()
local playerProductKey = "player_" .. receiptInfo.PlayerId .. receiptInfo.PurchaseId ds:IncrementAsync(playerProductKey, 1)
-- tell ROBLOX that we have successfully handled the transaction return Enum.ProductPurchaseDecision.PurchaseGranted else print("Went into script and returned false") end end --
Signature: [LMaD L2D God] |
|
|
| Report Abuse |
|
|
|
| 25 Apr 2015 08:46 PM |
| The wiki gives examples for this. It is an event, not a callback. At least, I'm pretty sure. Also, check the parameters it uses. Oh, and you can't return things through callbacks, can you? |
|
|
| Report Abuse |
|
|
|
| 25 Apr 2015 08:52 PM |
There is a thing called the output. Use it next time.
local MarketplaceService = game:GetService("MarketplaceService") local ds = game:GetService("DataStoreService"):GetDataStore("Purchases")
local productid = 23489526
MarketplaceService.ProcessReceipt = function(receiptInfo) for i, player in ipairs(game.Players:GetChildren()) do print("In the start of the script") if player.userId == receiptInfo.PlayerId then print("After user ID") local h = player.Character:FindFirstChild("Humanoid") local z = game.Players:FindFirstChild(h.Parent.Name) if receiptInfo.ProductId == productid then print("After comparing IDs") p.leaderstats.Cash.Value = p.leaderstats.Cash.Value + 75 local hint = Instance.new('Message') hint.Text = "Thank you so much for the purchase"..player.Name.."!" hint.Parent = player.PlayerGui wait(3) hint:Destroy() local playerProductKey = "player_" .. receiptInfo.PlayerId .. receiptInfo.PurchaseId ds:IncrementAsync(playerProductKey, 1) return Enum.ProductPurchaseDecision.PurchaseGranted end end end end |
|
|
| Report Abuse |
|
|
anaIyze
|
  |
| Joined: 29 May 2014 |
| Total Posts: 2048 |
|
|
| 25 Apr 2015 08:55 PM |
"print("Went into script and returned false")"
lool |
|
|
| Report Abuse |
|
|
|
| 25 Apr 2015 08:59 PM |
| Remove the DataStore check, since that prevents it from being bought multiple times. |
|
|
| Report Abuse |
|
|
|
| 25 Apr 2015 09:04 PM |
Still doesn't work. The print statements aren't coming through, so it isn't running at all.
Here's the localscript I have inside the GUI to purchase the devProduct:
-- local button = script.Parent local MarketplaceService = game:GetService("MarketplaceService")
local productid = 23489526
button.MouseButton1Click:connect(function(player)
player = script.Parent.Parent.Parent.Parent --this tells it who to prompt, the player who this gui is parented to
MarketplaceService:PromptProductPurchase(player, productid)
end) --
Signature: [LMaD L2D God] |
|
|
| Report Abuse |
|
|
|
| 25 Apr 2015 09:07 PM |
| Did you try it with the one I posted? |
|
|
| Report Abuse |
|
|
|
| 25 Apr 2015 09:11 PM |
Yes. Here's exactly how I have it in studio:
Inside ServerScriptStorage>Script: -- local MarketplaceService = game:GetService("MarketplaceService") local ds = game:GetService("DataStoreService"):GetDataStore("Purchases")
local productid = 23489526
MarketplaceService.ProcessReceipt = function(receiptInfo) for i, player in ipairs(game.Players:GetChildren()) do print("In the start of the script") if player.userId == receiptInfo.PlayerId then print("After user ID") local h = player.Character:FindFirstChild("Humanoid") local z = game.Players:FindFirstChild(h.Parent.Name) if receiptInfo.ProductId == productid then print("After comparing IDs") p.leaderstats.Cash.Value = p.leaderstats.Cash.Value + 75 local hint = Instance.new('Message') hint.Text = "Thank you so much for the purchase"..player.Name.."!" hint.Parent = player.PlayerGui wait(3) hint:Destroy() local playerProductKey = "player_" .. receiptInfo.PlayerId .. receiptInfo.PurchaseId ds:IncrementAsync(playerProductKey, 1) return Enum.ProductPurchaseDecision.PurchaseGranted end end end end --
Inside StarterGui>ScreenGui>TextButon>LocalScript: -- local button = script.Parent local MarketplaceService = game:GetService("MarketplaceService")
local productid = 23489526
button.MouseButton1Click:connect(function(player)
player = script.Parent.Parent.Parent.Parent --this tells it who to prompt, the player who this gui is parented to
MarketplaceService:PromptProductPurchase(player, productid)
end) --
Signature: [LMaD L2D God] |
|
|
| Report Abuse |
|
|
|
| 25 Apr 2015 09:19 PM |
local MarketplaceService = game:GetService("MarketplaceService") local ds = game:GetService("DataStoreService"):GetDataStore("Purchases")
local productid = 23489526
MarketplaceService.ProcessReceipt = function(receiptInfo) for i, player in ipairs(game.Players:GetChildren()) do print("In the start of the script") if player.userId == receiptInfo.PlayerId then print("After user ID") local h = player.Character:FindFirstChild("Humanoid") local z = game.Players:FindFirstChild(h.Parent.Name) if receiptInfo.ProductId == productid then print("After comparing IDs") player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 75 local hint = Instance.new('Message') hint.Text = "Thank you so much for the purchase"..player.Name.."!" hint.Parent = player.PlayerGui wait(3) hint:Destroy() local playerProductKey = "player_" .. receiptInfo.PlayerId .. receiptInfo.PurchaseId ds:IncrementAsync(playerProductKey, 1) return Enum.ProductPurchaseDecision.PurchaseGranted end end end end |
|
|
| Report Abuse |
|
|
|
| 25 Apr 2015 09:39 PM |
Doesn't work.
Signature: [LMaD L2D God] |
|
|
| Report Abuse |
|
|