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

Why would this Devproduct script work in Studio, but not in Play?

Asked by 6 years ago

So, this is a devproduct script, located in the ServerScriptService. The accompanying Shop GUI is in the Starter GUI. When I test it in studio, and click the GUI, I recive the money from paying in robux. However, when I purchase more than once, the amount of game dollars I get is more than when I bought for in robux. I'm not exactly sure why. Also, my main problem is that in Play, I get no ingame cash from purchasing with robux. I've seen similar posts about this and maybe it has to do with the script not being local? I'm not sure, maybe it's something in the script itself. If you could help let me know. Here's the script, Thank you!

game.StarterGui.ResetPlayerGuiOnSpawn = false

local MarketplaceService = game:GetService("MarketplaceService")

function getPlayerFromId(id)
    for i,v in pairs(game.Players:GetChildren()) do
        if v.userId == id then
            return v
        end
    end
    return nil
end

MarketplaceService.ProcessReceipt = function(receiptInfo)
    local productId = receiptInfo.ProductId
    local playerId = receiptInfo.PlayerId
    local player = getPlayerFromId(playerId)
    local productName 
    if productId == 35803838 then
        productName = "$5,000"
        local cashmoney = game.ServerStorage.PlayerMoney:FindFirstChild(player.Name)
        if cashmoney then
            cashmoney.Value = cashmoney.Value + 5000
        end
    elseif productId == 35803911 then
        productName = "$25,000!"
        local cashmoney = game.ServerStorage.PlayerMoney:FindFirstChild(player.Name)
        if cashmoney then
            cashmoney.Value = cashmoney.Value + 25000
        end
        elseif productId == 32804673 then
        productName = "$100,000!"
        local cashmoney = game.ServerStorage.PlayerMoney:FindFirstChild(player.Name)
        if cashmoney then
            cashmoney.Value = cashmoney.Value + 100000
        end
    elseif productId == 35803946 then
        productName = "$1,00,000!"
        local cashmoney = game.ServerStorage.PlayerMoney:FindFirstChild(player.Name)
        if cashmoney then
            cashmoney.Value = cashmoney.Value + 1000000
        end
        elseif productId == 32804689 then
        productName = "$1,000,000!"
        local cashmoney = game.ServerStorage.PlayerMoney:FindFirstChild(player.Name)
        if cashmoney then
            cashmoney.Value = cashmoney.Value + 1000000
        end
    elseif productId == 35803720 then
        productName = "+15 Walkspeed"
        local char = player.Character
        if char then
            local human = char:FindFirstChild("Humanoid")
            if human then
                human.WalkSpeed = human.WalkSpeed + 15
            end
        end
    elseif productId == 35803755 then
        productName = "Turret"
        game.Lighting.SentryTurret:Clone().Parent=player.Backpack
    end
    game.BadgeService:AwardBadge(0)
    local message = Instance.new("Hint",workspace)
    message.Text = player.Name.." purchased "..productName.."!"
    coroutine.resume(coroutine.create(function()
        wait(2)
        message:destroy()
    end))

    return Enum.ProductPurchaseDecision.PurchaseGranted     
end

1 answer

Log in to vote
0
Answered by 6 years ago

I think purchases have to be done locally.

Ad

Answer this question