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

Why does only one dev product give me value when purchased and the other doesn't?

Asked by 4 years ago

Hey there!

Would anyone be able to help me with this script? I would really appreciate it.

Right, so this script (when purchased a dev product) won't work. I don't know is it the button script, or the script that has the MarketplaceService.ProcessReceipt in it.

Whenever I buy the first product it works and gives me, though when I buy the second, it doesn't work. Just doesn't give me no value.

Also the button script is located in a gui. Then, a frame with all the buttons in it. Just some extra information!

Would anyone know what the problem is?

Is it the button script or the main script?

I'd really love some help and thank you so much for reading. It means a lot and I really appreciate that you even clicked on this to help me. All that just means so much to me. :)

Button script:

01   for i,v in pairs(script.Parent.Buttons:GetChildren()) do
02       if v:isA("TextButton") then
03           v.MouseButton1Click:connect(function()
04           pcall(function()
05               if v:FindFirstChild("Pass") then
06               for i,v in pairs(script.Parent.Buttons:GetChildren()) do
07       if v:isA("TextButton") then
08           v.MouseButton1Click:connect(function()
09           pcall(function()
10               if v:FindFirstChild("Pass") then game.MarketplaceService:PromptPurchase(game.Players.LocalPlayer,tonumber(v.Name))          else game.MarketplaceService:PromptProductPurchase(game.Players.LocalPlayer,tonumber(v.Name))      
11 
12              end
13         end)
14 end)
15end
16end

Main script:

01game.StarterGui.ResetPlayerGuiOnSpawn = false
02old_fog = game.Lighting.FogStart
03local MarketplaceService = game:GetService("MarketplaceService")
04 
05function getPlayerFromId(id)
06 for i,v in pairs(game.Players:GetChildren()) do
07 if v.userId == id then
08 return v
09end
10 end
11  return nil
12end
13 
14    MarketplaceService.ProcessReceipt = function(receiptInfo)
15        local productId = receiptInfo.ProductId
View all 43 lines...

2 answers

Log in to vote
1
Answered by 4 years ago

The issue is in this section. You need to try and force yourself to indent properly or you will continue to have these issues. Where i marked below you didn't close this if statement, meaning the 'elseif' below it is inside the same if statement as the first product. Clean up the indention and make sure your if elses align correctly.

01    if productId == 1135297211 then
02 
03        local stats= game.ServerStorage.PlrFolder
04    local pf= stats:FindFirstChild(player.Name)
05 
06        stats:FindFirstChild(player.Name)
07    local strength = pf.Strength
08    if strength then -- right here
09            pf.Strength.Value = pf.Strength.Value + 5 
10  elseif
11         productId ==1135297212 then
12 
13    local stats= game.ServerStorage.PlrFolder
14        local pf= stats:FindFirstChild(player.Name)
15        stats:FindFirstChild(player.Name)
View all 23 lines...
0
How do I do that? SonGohan6 85 — 4y
0
in your case you would click Ctrl + A to select whole code and then Alt + Shift + F to format the document (Or button on top of studio called format document) imKirda 4491 — 4y
0
Thanks, but my script still doesn't work. SonGohan6 85 — 4y
0
Then you probably did something wrong. DinozCreates 1070 — 4y
View all comments (2 more)
0
But I get no such error in the console. So what would I do wrong? SonGohan6 85 — 4y
0
Again, you've stuck an if statement below a different if statement that can never happen. You need to fix the indention and your end placements. DinozCreates 1070 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

try this

01MarketplaceService = game:GetService("MarketplaceService")
02 
03MarketplaceService.ProcessReceipt = function(receiptInfo)
04local players = game.Players:GetPlayers()
05 
06currency = "strength"
07 
08done = 0
09 
10for i=1,#players do
11    if players[i].userId == receiptInfo.PlayerId then
12            if receiptInfo.ProductId == 1135297211   and done == 0 then
13            done = 1
14            players[i].leaderstats[currency].Value = players[i].leaderstats[currency].Value + 5
15            done = 0
16        end
17    end
18end
19return Enum.ProductPurchaseDecision.PurchaseGranted
20end

bottom script

1local productId = 1135297211
2local player = game.Players.LocalPlayer
3script.Parent.MouseButton1Click:connect(function()
4    game:GetService("MarketplaceService"):PromptProductPurchase(player, productId)
5end)

leaderstats script

01local DataStoreService = game:GetService("DataStoreService")
02local DataStore = DataStoreService:GetDataStore("strengthStats")
03 
04game.Players.PlayerAdded:Connect(function(Player)
05    local Leaderstats = Instance.new("Folder", Player)
06    Leaderstats.Name = "leaderstats"
07    local strength= Instance.new("IntValue", Leaderstats)
08    strength.Name = "strength"
09    strength.Value = 0  or DataStore
10    local Data = DataStore:GetAsync(Player.UserId)
11 
12 
13    if Data then
14        strength.Value = Data.Strange

Answer this question