generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Why doesn't the run after buying a devProduct?

Previous Thread :: Next Thread 
SparkIeFarts is not online. SparkIeFarts
Joined: 27 Sep 2008
Total Posts: 16166
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
Viscoelastic is not online. Viscoelastic
Joined: 04 May 2012
Total Posts: 269
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
nQqzRYVpIKA5jLP is not online. nQqzRYVpIKA5jLP
Joined: 05 Mar 2015
Total Posts: 4135
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 is not online. anaIyze
Joined: 29 May 2014
Total Posts: 2048
25 Apr 2015 08:55 PM
"print("Went into script and returned false")"

lool
Report Abuse
Viscoelastic is not online. Viscoelastic
Joined: 04 May 2012
Total Posts: 269
25 Apr 2015 08:59 PM
Remove the DataStore check, since that prevents it from being bought multiple times.
Report Abuse
SparkIeFarts is not online. SparkIeFarts
Joined: 27 Sep 2008
Total Posts: 16166
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
nQqzRYVpIKA5jLP is not online. nQqzRYVpIKA5jLP
Joined: 05 Mar 2015
Total Posts: 4135
25 Apr 2015 09:07 PM
Did you try it with the one I posted?
Report Abuse
SparkIeFarts is not online. SparkIeFarts
Joined: 27 Sep 2008
Total Posts: 16166
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
nQqzRYVpIKA5jLP is not online. nQqzRYVpIKA5jLP
Joined: 05 Mar 2015
Total Posts: 4135
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
SparkIeFarts is not online. SparkIeFarts
Joined: 27 Sep 2008
Total Posts: 16166
25 Apr 2015 09:39 PM
Doesn't work.


Signature: [LMaD L2D God]
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image