Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does my Developer Product sometimes work and sometimes not? [Self Solved]

Asked by 9 years ago

Look on the bottom for information about Client-Sided and Server-Sided code Server-Sided script (Regular Script Inside of the GUI):

local MarketplaceService = game:GetService("MarketplaceService")
local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
local productId = 22702178
local productId2 = 22702183

game.Players.PlayerAdded:connect(function()
    print("start")
local DeveloperProducts = game:GetService("MarketplaceService"):GetDeveloperProductsAsync():GetCurrentPage()
for _, DevProductContainer in pairs(DeveloperProducts) do
    for Field, Value in pairs(DevProductContainer) do
        print(Field .. ": " .. Value)
    end
    print(" ")
end
print("end")
end)


MarketplaceService.ProcessReceipt = function(receiptInfo) 


    for i, player in ipairs(game.Players:GetChildren()) do
        if player.userId == receiptInfo.PlayerId then
            if receiptInfo.ProductId == productId then
                player.Character.Humanoid.WalkSpeed = player.Character.Humanoid.WalkSpeed + 3
            end
        end
        if player.userId == receiptInfo.PlayerId then
            if receiptInfo.ProductId == productId2 then
                player.Character.Humanoid.WalkSpeed = player.Character.Humanoid.WalkSpeed + 2
            end
        end
    end 

    local playerProductKey = "p_" .. receiptInfo.PlayerId .. "_p_" .. receiptInfo.PurchaseId

    ds:IncrementAsync(playerProductKey, 1)  
    return Enum.ProductPurchaseDecision.PurchaseGranted     
end

The Client Sided script (LocalScript inside of StarterPack):

game.Players.LocalPlayer.PlayerGui:WaitForChild("Store")-- This is here because I was thrown an error about Store not existing
local RobuxSpeed = script.Parent.Parent.PlayerGui.Store.Holder.CoreGui.RIncreaseSpeed
local TixSpeed = script.Parent.Parent.PlayerGui.Store.Holder.CoreGui.TIncreaseSpeed
local productId = 22702178
local productId2 = 22702183


RobuxSpeed.MouseButton1Click:connect(function()
    game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer, productId)
end)

TixSpeed.MouseButton1Click:connect(function()
    game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer, productId2)
end)

Is the problem within my Client Sided script? I don't know how I would fix this because when I didn't use a Yield, I was given an error about Store not existing, so I added that and it worked for my test. I have noticed sometimes it doesn't work, I think only when multiple players in within a server.

This is activated by pressing a TextButton in the Store Gui.

0
Is it because of my WaitForChild() ? alphawolvess 1784 — 9y
0
That regular Script should probably be in ServerScriptService, not a GUI. Try there and see if it's still messing up. Your code doesn't look wrong at all, other than that. adark 5487 — 9y

Answer this question