So here I have seven donations to win, so far I’ve only done the first four. BUT!!! For some reason, when I made the first donation, the second worked. But when I finished the fourth, then of all began to perform only the third. That is, I click the sound of the click is played, and the purchase is offered, but here a reward to the player is not given. What is the problem?
here’s my local script
wait(0.4)
local tween = game:GetService("TweenService")
local main = script.Parent.Parent.donateWins.main
local openButton = script.Parent.Parent.UnderGui.Wins.BuyWins
local player = game:GetService("Players").LocalPlayer
local ld = player:WaitForChild("leaderstats")
local DonateSound = game:GetService("SoundService").donate
local donateID = 1600443774
local donateID2 = 1600466409
local donateID3 = 1600697377
local donateID4 = 1600701485
local function openTrainMenu() -- ОТКРЫВАЕМ
game:GetService("SoundService").click:Play()
local Info = TweenInfo.new(0.15)
local Tween = tween:Create(main, Info, {Position = UDim2.new(0.143, 0, 0.106, 0)})
Tween:Play()
game:GetService("Lighting").Blur.Enabled = true
tween:Create(game.Workspace.CurrentCamera, TweenInfo.new(0.2, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {FieldOfView = 90}):Play()
end
local function closeTrainMenu() -- ЗАКРЫВАЕМ
game:GetService("SoundService").click:Play()
local Info = TweenInfo.new(0.15)
local Tween = tween:Create(main, Info, {Position = UDim2.new(0.143, 0, 1, 0)})
Tween:Play()
game:GetService("Lighting").Blur.Enabled = false
tween:Create(game.Workspace.CurrentCamera, TweenInfo.new(0.2, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {FieldOfView = 70}):Play()
end
local function donate1() -- НАГРАДА ЗА ДОНАТ
ld.Wins.Value = ld.Wins.Value + 140
DonateSound:Play()
end
local function clickDonate1() -- КЛИК ДОНАТ 1
game:GetService("SoundService").click:Play()
game.MarketplaceService:PromptProductPurchase(player, donateID)
end
local function donate2() -- НАГРАДА ЗА ДОНАТ
ld.Wins.Value = ld.Wins.Value + 350
DonateSound:Play()
end
local function clickDonate2()-- КЛИК ДОНАТ 2
game:GetService("SoundService").click:Play()
game.MarketplaceService:PromptProductPurchase(player, donateID2)
end
local function donate3() -- НАГРАДА ЗА ДОНАТ
ld.Wins.Value = ld.Wins.Value + 910
DonateSound:Play()
end
local function clickDonate3()-- КЛИК ДОНАТ 3
game:GetService("SoundService").click:Play()
game.MarketplaceService:PromptProductPurchase(player, donateID3)
end
local function donate4() -- НАГРАДА ЗА ДОНАТ
ld.Wins.Value = ld.Wins.Value + 3150
print("donate 4")
DonateSound:Play()
end
local function clickDonate4()-- КЛИК ДОНАТ 4
print("click")
game:GetService("SoundService").click:Play()
game.MarketplaceService:PromptProductPurchase(player, donateID4)
end
game:GetService("ReplicatedStorage"):WaitForChild("Remotes").donateWins1.OnClientInvoke = donate1
game:GetService("ReplicatedStorage"):WaitForChild("Remotes").donateWins2.OnClientInvoke = donate2
game:GetService("ReplicatedStorage"):WaitForChild("Remotes").donateWins3.OnClientInvoke = donate3
game:GetService("ReplicatedStorage"):WaitForChild("Remotes").donateWins4.OnClientInvoke = donate4
main.pack1.MouseButton1Click:Connect(clickDonate1)
main.pack1.TouchTap:Connect(clickDonate1)
main.pack2.MouseButton1Click:Connect(clickDonate2)
main.pack2.TouchTap:Connect(clickDonate2)
main.pack3.MouseButton1Click:Connect(clickDonate3)
main.pack3.TouchTap:Connect(clickDonate3)
main.pack4.MouseButton1Click:Connect(clickDonate4)
main.pack4.TouchTap:Connect(clickDonate4)
openButton.MouseButton1Click:Connect(openTrainMenu)
openButton.TouchTap:Connect(openTrainMenu)
main.close.MouseButton1Click:Connect(closeTrainMenu)
main.close.TouchTap:Connect(closeTrainMenu)
and here’s my server script for the first purchase:
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Donate1 = ReplicatedStorage:WaitForChild("Remotes").donateWins1
local productFunctions = {}
-- ProductId 456456 awards 100 gold to the player
productFunctions[1600443774] = function(receipt, player)
local leaderstats = player:FindFirstChild("leaderstats")
local Money = leaderstats and leaderstats:FindFirstChild("Wins")
if Money then
Donate1:InvokeClient(player)
return true
end
end
local function processReceipt(receiptInfo)
local userId = receiptInfo.PlayerId
local productId = receiptInfo.ProductId
local player = Players:GetPlayerByUserId(userId)
if player then
-- Get the handler function associated with the product ID and attempt to run it
local handler = productFunctions[productId]
local success, result = pcall(handler, receiptInfo, player)
if success then
-- The player has received their benefits!
-- return PurchaseGranted to confirm the transaction.
return Enum.ProductPurchaseDecision.PurchaseGranted
else
warn("Failed to process receipt:", receiptInfo, result)
end
end
-- the player's benefits couldn't be awarded.
-- return NotProcessedYet to try again next time the player joins.
return Enum.ProductPurchaseDecision.NotProcessedYet
end
-- Set the callback; this can only be done once by one script on the server!
MarketplaceService.ProcessReceipt = processReceipt
this script is taken from roblox studio documentation. And here is the second script for the second purchase, if anything they are almost no different:
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Donate2 = ReplicatedStorage:WaitForChild("Remotes").donateWins2
local productFunctions = {}
-- ProductId 456456 awards 100 gold to the player
productFunctions[1600466409] = function(receipt, player)
local leaderstats = player:FindFirstChild("leaderstats")
local Money = leaderstats and leaderstats:FindFirstChild("Wins")
if Money then
Donate2:InvokeClient(player)
return true
end
end
local function processReceipt(receiptInfo)
local userId = receiptInfo.PlayerId
local productId = receiptInfo.ProductId
local player = Players:GetPlayerByUserId(userId)
if player then
-- Get the handler function associated with the product ID and attempt to run it
local handler = productFunctions[productId]
local success, result = pcall(handler, receiptInfo, player)
if success then
-- The player has received their benefits!
-- return PurchaseGranted to confirm the transaction.
return Enum.ProductPurchaseDecision.PurchaseGranted
else
warn("Failed to process receipt:", receiptInfo, result)
end
end
-- the player's benefits couldn't be awarded.
-- return NotProcessedYet to try again next time the player joins.
return Enum.ProductPurchaseDecision.NotProcessedYet
end
-- Set the callback; this can only be done once by one script on the server!
MarketplaceService.ProcessReceipt = processReceipt
here’s the third script:
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Donate3 = ReplicatedStorage:WaitForChild("Remotes").donateWins3
local productFunctions = {}
-- ProductId 456456 awards 100 gold to the player
productFunctions[1600697377] = function(receipt, player)
local leaderstats = player:FindFirstChild("leaderstats")
local Money = leaderstats and leaderstats:FindFirstChild("Wins")
if Money then
Donate3:InvokeClient(player)
return true
end
end
local function processReceipt(receiptInfo)
local userId = receiptInfo.PlayerId
local productId = receiptInfo.ProductId
local player = Players:GetPlayerByUserId(userId)
if player then
-- Get the handler function associated with the product ID and attempt to run it
local handler = productFunctions[productId]
local success, result = pcall(handler, receiptInfo, player)
if success then
-- The player has received their benefits!
-- return PurchaseGranted to confirm the transaction.
return Enum.ProductPurchaseDecision.PurchaseGranted
else
warn("Failed to process receipt:", receiptInfo, result)
end
end
-- the player's benefits couldn't be awarded.
-- return NotProcessedYet to try again next time the player joins.
return Enum.ProductPurchaseDecision.NotProcessedYet
end
-- Set the callback; this can only be done once by one script on the server!
MarketplaceService.ProcessReceipt = processReceipt
and here’s the final four:
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Donate4 = ReplicatedStorage:WaitForChild("Remotes").donateWins4
local productFunctions = {}
-- ProductId 456456 awards 100 gold to the player
productFunctions[1600701485] = function(receipt, player)
local leaderstats = player:FindFirstChild("leaderstats")
local Money = leaderstats and leaderstats:FindFirstChild("Wins")
if Money then
Donate4:InvokeClient(player)
return true
end
end
local function processReceipt(receiptInfo)
local userId = receiptInfo.PlayerId
local productId = receiptInfo.ProductId
local player = Players:GetPlayerByUserId(userId)
if player then
-- Get the handler function associated with the product ID and attempt to run it
local handler = productFunctions[productId]
local success, result = pcall(handler, receiptInfo, player)
if success then
-- The player has received their benefits!
-- return PurchaseGranted to confirm the transaction.
return Enum.ProductPurchaseDecision.PurchaseGranted
else
warn("Failed to process receipt:", receiptInfo, result)
end
end
-- the player's benefits couldn't be awarded.
-- return NotProcessedYet to try again next time the player joins.
return Enum.ProductPurchaseDecision.NotProcessedYet
end
-- Set the callback; this can only be done once by one script on the server!
MarketplaceService.ProcessReceipt = processReceipt
that’s it. My question is why only the third one works, although the previous ones worked before?