So I am having some problems with my Developer Product Perk Shop in my game. I have this script to allow people to get Speed, Health, and Gear when they buy one of my Developer products.
local MarketplaceService = game:GetService("MarketplaceService")
local AddHealthID = 22137556 --ENTER
local AddSpeedID = 22137544 --PASS
local AddGearID = 22137570 --IDS
local AddGear2ID = 22137564 --IDS
local AddGear3ID = 22137575 --HERE
local AddGear4ID = 22137566 --IDS
local PurchaseHistory = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
MarketplaceService.ProcessReceipt = function(receiptInfo)
local playerProductKey = receiptInfo.PlayerId .. ":" .. receiptInfo.PurchaseId
if PurchaseHistory:GetAsync(playerProductKey) then
return Enum.ProductPurchaseDecision.PurchaseGranted
end
for i, player in ipairs(game.Players:GetPlayers()) do
if player.userId == receiptInfo.PlayerId then
if receiptInfo.ProductId == AddHealthID then
player.Character.Humanoid.MaxHealth = player.Character.Humanoid.MaxHealth + 50 --Adds 50 to their current health
player.Character.Humanoid.Health = player.Character.Humanoid.MaxHealth
end
if receiptInfo.ProductId == AddSpeedID then
player.Character.Humanoid.WalkSpeed = player.Character.Humanoid.WalkSpeed + 15 -- Adds 5 to their current Walkspeed
end
if receiptInfo.ProductId == AddGearID then
game.ReplicatedStorage.GravityCoil:Clone().Parent = player.Backpack -- put the gear in ReplicatedStorage then put the name of the gear in the GEARNAMEHERE
-- game.ReplicatedStorage.GEARNAMEHERE:Clone().Parent = player.StarterGear -- Add this back in if you want them to get this item till they leave the game, Like renting it
end
if receiptInfo.ProductId == AddGear2ID then
game.ReplicatedStorage.LockonLauncher:Clone().Parent = player.Backpack -- put the gear in ReplicatedStorage then put the name of the gear in the GEARNAMEHERE
-- game.ReplicatedStorage.GEARNAMEHERE:Clone().Parent = player.StarterGear -- Add this back in if you want them to get this item till they leave the game, Like renting it
end
if receiptInfo.ProductId == AddGear3ID then
game.ReplicatedStorage.JetPack:Clone().Parent = player.Backpack -- put the gear in ReplicatedStorage then put the name of the gear in the GEARNAMEHERE
-- game.ReplicatedStorage.GEARNAMEHERE:Clone().Parent = player.StarterGear -- Add this back in if you want them to get this item till they leave the game, Like renting it
end
if receiptInfo.ProductId == AddGear4ID then
game.ReplicatedStorage.EpicLaser:Clone().Parent = player.Backpack -- put the gear in ReplicatedStorage then put the name of the gear in the GEARNAMEHERE
-- game.ReplicatedStorage.GEARNAMEHERE:Clone().Parent = player.StarterGear -- Add this back in if you
end
end
end
PurchaseHistory:SetAsync(playerProductKey, true)
return Enum.ProductPurchaseDecision.PurchaseGranted
end
This works perfectly fine, but I added this script that also works, but it adds cash to there leader stats to use on things in the tycoon.
local MarketplaceService = Game:GetService("MarketplaceService")
local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
CASHID = 23781403
MarketplaceService.ProcessReceipt = function(receiptInfo)
local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_product_" .. receiptInfo.ProductId
local numberBought = ds:IncrementAsync(playerProductKey, 1)
for i,v in pairs (game.Players:GetChildren()) do
if v.userId == receiptInfo.PlayerId then
if receiptInfo.ProductId == CASHID then
lds = v:FindFirstChild("leaderstats")
if lds ~= nil then
cs = lds:FindFirstChild("Cash")
if cs ~= nil then
cs.Value = cs.Value + 10,000
end
end
end
end
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
These two scripts both work, but when they are both in the same game running at the same time the cash script causes the other script to completely stop working at all. It probably runs into something inside of the scripts that make them not compatible, but I was wondering how I could fix this problem. Maybe forming the two scripts together so they run as one? Please help me!
