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

Giving coins gamepass that doesn't work?

Asked by 4 years ago
Edited 4 years ago

This is the script in ServerScriptService

game.StarterGui.ResetPlayerGuiOnSpawn = false
old_fog = game.Lighting.FogStart
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 == 958879047 then
    local Coins = player.leaderstats:FindFirstChild("Coins")
        if Coins then
            Coins.Value = Coins.Value + 1000
        end

-------------------------------------------------------------------

elseif productId == 958879379 then
    local Coins = player.leaderstats:FindFirstChild("Coins")
        if Coins then
            Coins.Value = Coins.Value + 5000
        end

-------------------------------------------------------------------

elseif productId == 958879657 then
    local Coins = player.leaderstats:FindFirstChild("Coins")
        if Coins then
            Coins.Value = Coins.Value + 10000
        end

-------------------------------------------------------------------

elseif productId == 958879909 then
    local Coins = player.leaderstats:FindFirstChild("Coins")
        if Coins then
            Coins.Value = Coins.Value + 25000
        end

    -------------------------------------------------------------------
    elseif productId == 958880690 then
    local Coins = player.leaderstats:FindFirstChild("Coins")
        if Coins then
            Coins.Value = Coins.Value + 50000
        end

    elseif productId == 958881104 then
    local Coins = player.leaderstats:FindFirstChild("Coins")
        if Coins then
            Coins.Value = Coins.Value + 100000
        end

    elseif productId == 958881905 then
    local Coins = player.leaderstats:FindFirstChild("Coins")
        if Coins then
            Coins.Value = Coins.Value + 500000
        end

    -------------------------------------------------------------------
end
return Enum.ProductPurchaseDecision.PurchaseGranted     

end`

This is the script in the ShopGui -> Buttons -> (All the buttons ID) with this in the gui folder

for i,v in pairs(script.Parent.Buttons:GetChildren()) do
    if v:isA("TextButton") then
        v.MouseButton1Click:connect(function()
            pcall(function()
                if v:FindFirstChild("Pass") then
                    game.MarketplaceService:PromptPurchase(game.Players.LocalPlayer,tonumber(v.Name))
                else    
                    game.MarketplaceService:PromptProductPurchase(game.Players.LocalPlayer,tonumber(v.Name))
                end
            end)
        end)
    end
end

It actually worked yesterday but now it doesn't. I have no idea why. When you click +1000 coins ingame the gamepass / product pops up but when i buy it it doesn't give anything as it did yesterday. Anyone who knows how to fix this?

My Datastore in case it could be something that does so it doesn't work

local datastore = game:GetService("DataStoreService"):GetDataStore("GameStore35") 

game.Players.PlayerAdded:connect(function(player)
    local leaderstats = Instance.new("IntValue")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local Coins = Instance.new("IntValue") 
    Coins.Name = "Coins" 
    Coins.Parent = leaderstats

    local Eggs = Instance.new("IntValue") 
    Eggs.Name = "Eggs" 
    Eggs.Parent = leaderstats

    local Rebirths = Instance.new("IntValue") 
    Rebirths.Name = "Rebirths" 
    Rebirths.Parent = leaderstats
    Rebirths.Value = 1

    local key = "user-" .. player.userId

    local storeditems = datastore:GetAsync(key)
    if storeditems then
        Coins.Value = storeditems[1] 
        Eggs.Value = storeditems[2] 
        Rebirths.Value = storeditems[3]
    else
        local items = {Coins.Value, Eggs.Value, Rebirths.Value} 
        datastore:SetAsync(key, items)
    end
end)

game.Players.PlayerRemoving:connect(function(player)
    local items = {player.leaderstats.Coins.Value, player.leaderstats.Eggs.Value, player.leaderstats.Rebirths.Value} 
    local key = "user-" .. player.userId

    datastore:SetAsync(key, items)
end)
0
Please reformat the messed up codeblocks... Are there any errors in the output associated with this? InfinityDesign 280 — 4y
0
No errors at all asbjornbonde 32 — 4y
0
I don't know if it is my Datastore that does so it the coins doesn't payout. asbjornbonde 32 — 4y
View all comments (13 more)
0
You can find the player with this line; "game:GetService('Players'):GetPlayerByUserId(playerId)" NiniBlackJackQc 1562 — 4y
0
The difference is, developer products is in-game buyable and is an automatic transaction, multiple times. Gamepasses are a one-time buy, that gives the player the ability that you allow them to have once they join the game. killerbrenden 1537 — 4y
0
A developer product. Everything works fine killerbrenden, but when i buy the product nothing happens asbjornbonde 32 — 4y
0
Try what NiniBlackJackQc did, use GetPlayerByuUserId(playerId). killerbrenden 1537 — 4y
0
Where should i use that tho Killerbrenden? asbjornbonde 32 — 4y
0
local player = game:GetService('Players'):GetPlayerByUserId(playerId) NiniBlackJackQc 1562 — 4y
0
Change the line 17 to that NiniBlackJackQc 1562 — 4y
0
Still doesn't work asbjornbonde 32 — 4y
0
Put a prints everywhere NiniBlackJackQc 1562 — 4y
0
Where should i print() ? asbjornbonde 32 — 4y
0
I tried to print in the middle if Coins then ((((((( print(1) )))))) Coins.Value = Coins.Value + 1000 and it did work asbjornbonde 32 — 4y
0
I found out what the problem was myself :D it was a script in another folder that mate everything to not work asbjornbonde 32 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

Found out what the problem was

0
You should put what the problem was so that other people, if they have this problem, know how to fix it. MrLonely1221 701 — 4y
0
The problem was another script i made years ago in the same folder that fucked up the script so noone else will have the same problem and that is why i didn't write why asbjornbonde 32 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

I'm not sure about the problem, but I used your code and did what NiniBlackJackQc said to do and it worked perfectly fine.

This is what I would put in your LocalScript

local MS = game:GetService("MarketplaceService")
MS:PromptProductPurchase(player,PUT_DEVELOPER_PRODUCT_ID_HERE)

This will prompt the player with the option of purchasing the custom developer product.

This is what I would put in your ServerScript

game.StarterGui.ResetPlayerGuiOnSpawn = false
old_fog = game.Lighting.FogStart
local MarketplaceService = game:GetService("MarketplaceService")

MarketplaceService.ProcessReceipt = function(receiptInfo)
    local productId = receiptInfo.ProductId
    local playerId = receiptInfo.PlayerId
    local player = game:GetService("Players"):GetPlayerByUserId(playerId) --// Everything is the same besides this.
    local productName

    -------------------------------------------------------------------

if productId == 958879047 then
    local Coins = player.leaderstats:FindFirstChild("Coins")
        if Coins then
            Coins.Value = Coins.Value + 1000
        end

    -------------------------------------------------------------------
end

return Enum.ProductPurchaseDecision.PurchaseGranted     

end

This worked for me, if this helped you, let me know by selecting this as the answer!

~killerbrenden

Answer this question