Problem with multiple donations for wins

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?

2 Likes

Out of context but I don’t think selling wins is a good marketing tactic, it looks weird to me and I haven’t seen it anywhere else. Also, it ruins the authenticity of having wins in the first place and it may discourage players from spending a large amount of time in your game, something that you must avoid if you want to increase player engagement and concurrent amounts.

3 Likes

You are doing it not very effeciently, also u shouldnt add values (from leaderstats) in local script.
here`s the local script i think is the best to use:

local tween = game:GetService("TweenService")
local mps = game:GetService("MarketplaceService")

local main = script.Parent.Parent:WaitForChild("donateWins"):WaitForChild("main")
local openButton = script.Parent.Parent:WaitForChild("UnderGui"):WaitForChild("Wins"):WaitForChild("BuyWins")

local player = game:GetService("Players").LocalPlayer
local ld = player:WaitForChild("leaderstats")

local DonateSound = game:GetService("SoundService"):WaitForChild("donate")
local clickSound = game:GetService("SoundService"):WaitForChild("click")

local function openTrainMenu()
	clickSound: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()
	clickSound: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

for i, button in main:GetChildren() do
	if button:FindFirstChild("Id") then -- add int value inside your button called "Id" and set the value of it to your id
		button.MouseButton1Click:Connect(function()
			mps:PromptProductPurchase(player, button.Id.Value)
		end)
		button.TouchTap:Connect(function()
			mps:PromptProductPurchase(player, button.Id.Value)
		end)
	end
end

server script u can use:

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local ids = {
	{Id = 1111,
		Amount = 3426,},
	{Id = 1111,
		Amount = 4,},
	{Id = 44215,
		Amount = 100075400,},
	{Id = 333,
		Amount = 55,},
}

local function AddMoney(receiptInfo)
	local ProductId = receiptInfo.ProductId
	local item
	for i, product in pairs(ids) do
		if product.Id == ProductId then
			item = product
			break
		end
	end
	if not item then return Enum.ProductPurchaseDecision.NotProcessedYet end
		local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
	if not player then return Enum.ProductPurchaseDecision.NotProcessedYet end
	local leds = player:WaitForChild("leaderstats")
	leds.Wins.Value += ids[ProductId].Amount
return  Enum.ProductPurchaseDecision.PurchaseGranted
end

MarketplaceService.ProcessReceipt = AddMoney

and thats it! you dont need any bindable functions. Just add IntValue called “Id” to every button and paste id there. Change ids and reward that u want in server script
If i messed something up, let me know, because i hadnt test it but it should work.

2 Likes