doneyes
|
  |
| Joined: 21 Mar 2008 |
| Total Posts: 3466 |
|
|
| 25 Sep 2014 06:23 PM |
I have a script that lets the player buy using a dev product, but I want to do a quick check to see if they purchased it to then apply the reward.
The thing is, this dev project is something that should be bought over and over and doesn't need data saving.
So it seems rather simple, but I can't figure it out. Any ideas? |
|
|
| Report Abuse |
|
|
doneyes
|
  |
| Joined: 21 Mar 2008 |
| Total Posts: 3466 |
|
| |
|
morash
|
  |
| Joined: 22 May 2010 |
| Total Posts: 5834 |
|
|
| 25 Sep 2014 09:00 PM |
Something I came up with some months ago while working with my development team. Really easy to use. Just add a function into the ProductFunctions dictionary with the index being the product Id and the value being a function with an input of the player's Id doing what you want the product to give. The stuff below it is setting the callback for ProcessReceipt to a function that calls the functions in the ProductFunctions dictionary.
ProductFunctions = { --This is called a dictionary btw. [ProductId] = function(playerId) --Code to do stuff you want end }
game:GetService("MarketplaceService").ProcessReceipt = function(receipt) if ProductFunctions[receipt.ProductId] then ProductFunctions[receipt.ProductId](receipt.PlayerId) end end |
|
|
| Report Abuse |
|
|
doneyes
|
  |
| Joined: 21 Mar 2008 |
| Total Posts: 3466 |
|
|
| 26 Sep 2014 06:53 AM |
| I will check this out in for sure. Thanks. It looks like what I am wanting. |
|
|
| Report Abuse |
|
|
doneyes
|
  |
| Joined: 21 Mar 2008 |
| Total Posts: 3466 |
|
|
| 27 Sep 2014 12:48 AM |
I feel dumb for not know how to set this up, but this is what I have. It's not giving errors and not printing that I have bought the item.
player = game.Players.LocalPlayer
MarketplaceService = Game:GetService("MarketplaceService") ProductId = 21285138
function select() print("This buy button has been clicked.") gold = player:FindFirstChild("Gold") if gold then MarketplaceService:PromptProductPurchase(player, ProductId) print("Item has been bought?") end end
script.Parent.MouseButton1Down:connect(select)
ProductFunctions = { --This is called a dictionary btw. [ProductId] = function(playerId) --Code to do stuff you want print("you now own this!") end }
game:GetService("MarketplaceService").ProcessReceipt = function(receipt) if ProductFunctions[receipt.ProductId] then ProductFunctions[receipt.ProductId](receipt.PlayerId) end end |
|
|
| Report Abuse |
|
|
CrowClaws
|
  |
| Joined: 04 Jul 2010 |
| Total Posts: 4466 |
|
|
| 27 Sep 2014 12:58 AM |
Wait. Not sure but I was reading about it a while ago and it said if you don't reture like "GrantedSomething" it will not give you the money. |
|
|
| Report Abuse |
|
|
morash
|
  |
| Joined: 22 May 2010 |
| Total Posts: 5834 |
|
|
| 27 Sep 2014 10:22 AM |
| ^True, accidentally left that part out ;-;. The code I've given you has to be done on the server, not the client, or regular script, not local script. |
|
|
| Report Abuse |
|
|
doneyes
|
  |
| Joined: 21 Mar 2008 |
| Total Posts: 3466 |
|
|
| 27 Sep 2014 10:59 AM |
| Ah okay. So once I move it to a server script, how do I solve the issue? I'm trying to get it done by tonight. |
|
|
| Report Abuse |
|
|
doneyes
|
  |
| Joined: 21 Mar 2008 |
| Total Posts: 3466 |
|
|
| 27 Sep 2014 11:09 AM |
| Welp, it works like a charm. Thank you! |
|
|
| Report Abuse |
|
|
doneyes
|
  |
| Joined: 21 Mar 2008 |
| Total Posts: 3466 |
|
|
| 27 Sep 2014 11:18 AM |
What would I set to nil so that it can be rebought over and over without the command firing multiple times?
Right now when I buy it once, it displays the items has been bought. Then if I buy it again that game, it will display it twice. 3 buys and it displays 3 times, you get it.
I assume something can be set to nil after the reward is distributed so it resets it? |
|
|
| Report Abuse |
|
|
doneyes
|
  |
| Joined: 21 Mar 2008 |
| Total Posts: 3466 |
|
|
| 27 Sep 2014 11:23 AM |
| I set playerID to nil so if studio ever wants to publish my game, I feel it will work. |
|
|
| Report Abuse |
|
|
doneyes
|
  |
| Joined: 21 Mar 2008 |
| Total Posts: 3466 |
|
|
| 27 Sep 2014 11:24 AM |
| I'm still getting the same issue. I'll keep playing around with it. If anyone knows the correct way to do this, it's very appreciated. |
|
|
| Report Abuse |
|
|
doneyes
|
  |
| Joined: 21 Mar 2008 |
| Total Posts: 3466 |
|
|
| 27 Sep 2014 11:50 AM |
| I went the easy path and disabled / enabled the script so it just resets. Thanks for help! |
|
|
| Report Abuse |
|
|
doneyes
|
  |
| Joined: 21 Mar 2008 |
| Total Posts: 3466 |
|
|
| 27 Sep 2014 01:48 PM |
| the script stops working if there are more than just 1 buttons. Whats up with that? |
|
|
| Report Abuse |
|
|
doneyes
|
  |
| Joined: 21 Mar 2008 |
| Total Posts: 3466 |
|
| |
|