This is my script for purchasing currency in my game... But players are complaining that this doesn't work sometimes... Why?
local MarketplaceService = game:GetService("MarketplaceService")
MarketplaceService.ProcessReceipt = function(receiptInfo)
if receiptInfo.ProductId == 25740543 then--1000
local players = game.Players:GetChildren()
for i=1,#players do
if players[i].userId == receiptInfo.PlayerId then
players[i].leaderstats["Tokens"].Value = players[i].leaderstats["Tokens"].Value + 1000
local gui = game.ServerStorage.assets.EXTRAINFO:Clone()
gui.TextLabel.Text = (players[i].Name.." just bought $1,000 Tokens")
gui.Parent = game.Workspace.game.Gui
end
end
elseif receiptInfo.ProductId == 25740553 then--7500
local players = game.Players:GetChildren()
for i=1,#players do
if players[i].userId == receiptInfo.PlayerId then
players[i].leaderstats["Tokens"].Value = players[i].leaderstats["Tokens"].Value + 7500
local gui = game.ServerStorage.assets.EXTRAINFO:Clone()
gui.TextLabel.Text = (players[i].Name.." just bought $7,500 Tokens")
gui.Parent = game.Workspace.game.Gui
end
end
elseif receiptInfo.ProductId == 25740591 then--20,000
local players = game.Players:GetChildren()
for i=1,#players do
if players[i].userId == receiptInfo.PlayerId then
players[i].leaderstats["Tokens"].Value = players[i].leaderstats["Tokens"].Value + 20000
local gui = game.ServerStorage.assets.EXTRAINFO:Clone()
gui.TextLabel.Text = (players[i].Name.." just bought $20,000 Tokens")
gui.Parent = game.Workspace.game.Gui
end
end
elseif receiptInfo.ProductId == 25740608 then -- 1,000,000
local players = game.Players:GetChildren()
for i=1,#players do
if players[i].userId == receiptInfo.PlayerId then
players[i].leaderstats["Tokens"].Value = players[i].leaderstats["Tokens"].Value + 1000000
local gui = game.ServerStorage.assets.EXTRAINFO:Clone()
gui.TextLabel.Text = (players[i].Name.." just bought $1,000,000 Tokens")
gui.Parent = game.Workspace.game.Gui
end
end
elseif receiptInfo.ProductId == 27658062 then -- 1,000,000
local players = game.Players:GetChildren()
for i=1,#players do
if players[i].userId == receiptInfo.PlayerId then
local gueeeee = game.ServerStorage.assets.Trail:Clone()
gueeeee.Parent = players[i].PlayerGui.GUI
local gui = game.ServerStorage.assets.EXTRAINFO:Clone()
gui.TextLabel.Text = (players[i].Name.." just bought a custom trail!")
gui.Parent = game.Workspace.game.Gui
end
end
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
