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: Having trouble with Datastores & DevProducts

Previous Thread :: Next Thread 
devTools is not online. devTools
Joined: 06 Sep 2014
Total Posts: 7950
22 Jul 2015 03:17 PM
Basically I am trying to make it where you can buy this devProduct and then it will make you the DJ or put you in line for it, but only once. Right now when I join the server, it makes me DJ automatically even though I didn't purchase it in that specific server.

function FindPlayer(id)
local players = game.Players:GetChildren()
for i = 1, #players do
if players[i].userId == id then
return players[i]
end
end
return nil
end

local MarketplaceService = game:GetService("MarketplaceService")
local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")

MarketplaceService.ProcessReceipt = function(receiptInfo)
if Enum.ProductPurchaseDecision.PurchaseGranted and receiptInfo.ProductId == devId then
if FindPlayer(receiptInfo.PlayerId) ~= nil then
local p = FindPlayer(receiptInfo.PlayerId)
local dj = ds:GetAsync(receiptInfo.PlayerId .. " " .. receiptInfo.PurchaseId) or 0
if dj ~= receiptInfo.PurchaseId then
table.insert(signedUp,#signedUp+1,p)
ds:SetAsync(receiptInfo.PlayerId .. " " .. receiptInfo.PurchaseId, receiptInfo.PurchaseId)
end
end
end
end



| devTools || Sky Admiral of The Sky Clan of ROBLOX |
Report Abuse
devTools is not online. devTools
Joined: 06 Sep 2014
Total Posts: 7950
22 Jul 2015 03:18 PM
And yes, I have another script where it prompts them to buy the devProduct. All I am looking for is how to save the purchaseId for that server and in the next server, make sure that the purchaseId isn't the same as the one from the previous server.



| devTools || Sky Admiral of The Sky Clan of ROBLOX |
Report Abuse
devTools is not online. devTools
Joined: 06 Sep 2014
Total Posts: 7950
22 Jul 2015 03:31 PM
Bump
Please help :)



| devTools || Sky Admiral of The Sky Clan of ROBLOX |
Report Abuse
devTools is not online. devTools
Joined: 06 Sep 2014
Total Posts: 7950
22 Jul 2015 03:39 PM
bump



| devTools || Sky Admiral of The Sky Clan of ROBLOX |
Report Abuse
devTools is not online. devTools
Joined: 06 Sep 2014
Total Posts: 7950
22 Jul 2015 03:45 PM
bumpp



| devTools || Sky Admiral of The Sky Clan of ROBLOX |
Report Abuse
Happywalker is not online. Happywalker
Joined: 05 Mar 2010
Total Posts: 3672
22 Jul 2015 04:02 PM
Why save it if it's just for once
Report Abuse
devTools is not online. devTools
Joined: 06 Sep 2014
Total Posts: 7950
22 Jul 2015 04:46 PM
Because when I join the server, the if statement detects that I already bought that product so it adds me to the list right away.
I need it to compare the current server's purchase to the last saved purchase so it doesn't automatically put them in.


|devTools|
Report Abuse
devTools is not online. devTools
Joined: 06 Sep 2014
Total Posts: 7950
22 Jul 2015 05:25 PM
bump
Any other ways to do this?
Report Abuse
devTools is not online. devTools
Joined: 06 Sep 2014
Total Posts: 7950
22 Jul 2015 05:41 PM
b
Report Abuse
devTools is not online. devTools
Joined: 06 Sep 2014
Total Posts: 7950
22 Jul 2015 05:57 PM
bumpppp
cmonpls
Report Abuse
nQqzRYVpIKA5jLP is not online. nQqzRYVpIKA5jLP
Joined: 05 Mar 2015
Total Posts: 4135
22 Jul 2015 06:17 PM
local assetId = 00000

local marketplaceService = game:GetService("MarketplaceService")
local djStore = game:GetService("DataStoreService"):GetDataStore("DjPurchaseHistory")

local Dj = {}

--TODO: Implement this function
--And handle making players DJ
function Dj:SignUp(player, purchases)
if self.CurrentDj == nil then
self.CurrentDj = player
end
end

function playerAdded(player)
local djPurchases = djStore:GetAsync(player.userId) or 0

if djPurchases > 0 then
Dj:SignUp(player, djPurchases)
end
end

function processPurchase(receiptInfo)
local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)

if player then
if receiptInfo.ProductId == assetId then
local totalPurchases = 0

djStore:UpdateAsync(player.userId, function(oldValue)
oldValue = oldValue or 0
local newValue = oldValue + 1

totalPurchases = newValue
return newValue
end)

Dj:SignUp(player, totalPurchases)
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end

return Enum.ProductPurchaseDecision.NotProcessedYet
end

marketplaceService.ProcessReceipt = processPurchase
game.Players.PlayerAdded:connect(playerAdded)
Report Abuse
devTools is not online. devTools
Joined: 06 Sep 2014
Total Posts: 7950
22 Jul 2015 06:23 PM
hm ill have to tinker with this when I get home, but thanks!


|devTools|
Report Abuse
devTools is not online. devTools
Joined: 06 Sep 2014
Total Posts: 7950
22 Jul 2015 10:45 PM
Bump
That's a bit too complex for me to understand lol, I'm only intermediate and rather new with datastores. Could someone just show me how to have it save the purchaseid for the next time they do it so it checks if it is the current purchase rather than the last one or from a previous server?



| devTools || Sky Admiral of The Sky Clan of ROBLOX |
Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
22 Jul 2015 10:48 PM
http://wiki.roblox.com/index.php?title=API:Class/Players/GetPlayerByUserId
This link trumps your function

if Enum.ProductPurchaseDecision.PurchaseGranted and receiptInfo.ProductId == devId then
This is your problem I think
Report Abuse
devTools is not online. devTools
Joined: 06 Sep 2014
Total Posts: 7950
22 Jul 2015 11:13 PM
@cody
o thanks, it's working fine now :D



| devTools || Sky Admiral of The Sky Clan of ROBLOX |
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