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:
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 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
Main script:
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 == 1135297211 then local stats= game.ServerStorage.PlrFolder local pf= stats:FindFirstChild(player.Name) stats:FindFirstChild(player.Name) local strength = pf.Strength if strength then pf.Strength.Value = pf.Strength.Value + 5 elseif productId ==1135297212 then local stats= game.ServerStorage.PlrFolder local pf= stats:FindFirstChild(player.Name) stats:FindFirstChild(player.Name) local strength = pf.Strength if strength then pf.Strength.Value = pf.Strength.Value + 20 end end return Enum.ProductPurchaseDecision.PurchaseGranted end
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.
if productId == 1135297211 then local stats= game.ServerStorage.PlrFolder local pf= stats:FindFirstChild(player.Name) stats:FindFirstChild(player.Name) local strength = pf.Strength if strength then -- right here pf.Strength.Value = pf.Strength.Value + 5 elseif productId ==1135297212 then local stats= game.ServerStorage.PlrFolder local pf= stats:FindFirstChild(player.Name) stats:FindFirstChild(player.Name) local strength = pf.Strength if strength then pf.Strength.Value = pf.Strength.Value + 20 end end return Enum.ProductPurchaseDecision.PurchaseGranted end
try this
MarketplaceService = game:GetService("MarketplaceService") MarketplaceService.ProcessReceipt = function(receiptInfo) local players = game.Players:GetPlayers() currency = "strength" done = 0 for i=1,#players do if players[i].userId == receiptInfo.PlayerId then if receiptInfo.ProductId == 1135297211 and done == 0 then done = 1 players[i].leaderstats[currency].Value = players[i].leaderstats[currency].Value + 5 done = 0 end end end return Enum.ProductPurchaseDecision.PurchaseGranted end
bottom script
local productId = 1135297211 local player = game.Players.LocalPlayer script.Parent.MouseButton1Click:connect(function() game:GetService("MarketplaceService"):PromptProductPurchase(player, productId) end)
leaderstats script
local DataStoreService = game:GetService("DataStoreService") local DataStore = DataStoreService:GetDataStore("strengthStats") game.Players.PlayerAdded:Connect(function(Player) local Leaderstats = Instance.new("Folder", Player) Leaderstats.Name = "leaderstats" local strength= Instance.new("IntValue", Leaderstats) strength.Name = "strength" strength.Value = 0 or DataStore local Data = DataStore:GetAsync(Player.UserId) if Data then strength.Value = Data.Strange