Syntax Error: (39,10) Expected 'end' (to close 'function' at line 28), got 'elseif'; did you forget to close 'then' at line 36? What's happening?

This is my script
local MPS = game:GetService(“MarketplaceService”)
MPS.ProcessReceipt = function(info)
local userid = info.PlayerId
local productid = info.ProductId
local player = game.Players:GetPlayerByUserId(userid)
local leaderstats = game.Players.leaderstats
local Donation = leaderstats.Coins
if productid == 1681905809 then
Donation.Value += 5
elseif productid == 1681906701 then
Donation.Value += 10
end
elseif productid == 1681906702 then
Donation.Value += 100
end
if productid == 1681907949 then
Donation.Value += 1000
end
elseif productid == 1681908502 then
Donation.Value += 10000
end
end
I view a tutorial so the script can be bad…

local MPS = game:GetService("MarketplaceService")
MPS.ProcessReceipt = function(info)
	local userid = info.PlayerId
	local productid = info.ProductId
	local player = game.Players:GetPlayerByUserId(userid)
	local leaderstats = player.leaderstats
	local Donation = leaderstats.Coins
	if productid == 1681905809 then
		Donation.Value += 5
	elseif productid == 1681906701 then
		Donation.Value += 10
	elseif productid == 1681906702 then
	Donation.Value += 100
	elseif productid == 1681907949 then
	Donation.Value += 1000
	elseif productid == 1681908502 then
	Donation.Value += 10000
end
end
1 Like

One thing when using elseif is that you don’t put an end after everyone of them. You only put it after the last one, and MrOnlyKemal fixed it by removing the unnecessary ends that you had. You should remember this next time you use elseif. I have forgotten this before and I simply just removed ends until I found what I was doing wrong. Now, if there are any other errors than this won’t fix the entire script.

you could make a table for the products to make the script nicer and easier to manage.

local MPS = game:GetService("MarketplaceService")

-- Map product IDs to coin values
local productValues = {
    [1681905809] = 5,
    [1681906701] = 10,
    [1681906702] = 100,
    [1681907949] = 1000,
    [1681908502] = 10000
}

MPS.ProcessReceipt = function(info)
    local userid = info.PlayerId
    local productid = info.ProductId
    local player = game.Players:GetPlayerByUserId(userid)
    local leaderstats = player.leaderstats
    local Donation = leaderstats.Coins

    -- Check if the product ID exists in the table
    if productValues[productid] then
        Donation.Value += productValues[productid]
    end
end
1 Like

Use Roblox’s developer product tutorial:

Code:

--//Services
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

--//Tables
local productFunctions = {}

productFunctions[1681905809] = function(player)
	local leaderstats = player:FindFirstChild("leaderstats")
	local coins = leaderstats and leaderstats:FindFirstChild("Coins")

	if coins then
		coins.Value += 5
		return true
	end
end

productFunctions[1681906701] = function(player)
	local leaderstats = player:FindFirstChild("leaderstats")
	local coins = leaderstats and leaderstats:FindFirstChild("Coins")

	if coins then
		coins.Value += 10
		return true
	end
end

productFunctions[1681906702] = function(player)
	local leaderstats = player:FindFirstChild("leaderstats")
	local coins = leaderstats and leaderstats:FindFirstChild("Coins")

	if coins then
		coins.Value += 100
		return true
	end
end

productFunctions[1681907949] = function(player)
	local leaderstats = player:FindFirstChild("leaderstats")
	local coins = leaderstats and leaderstats:FindFirstChild("Coins")

	if coins then
		coins.Value += 1000
		return true
	end
end

productFunctions[1681908502] = function(player)
	local leaderstats = player:FindFirstChild("leaderstats")
	local coins = leaderstats and leaderstats:FindFirstChild("Coins")

	if coins then
		coins.Value += 10000
		return true
	end
end

--//Functions
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 developer product ID and attempt to run it
		local handler = productFunctions[productId]
		local success, result = pcall(handler, player)
		if success then
			-- The user 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 user's benefits couldn't be awarded.
	-- Return NotProcessedYet to try again next time the user joins.
	return Enum.ProductPurchaseDecision.NotProcessedYet
end

-- Set the callback; this can only be done once by one script on the server!
MarketplaceService.ProcessReceipt = processReceipt
1 Like

Me desaprecio el error, pero voy a revisar…

Mejor coloco el script completo:
local DS = game:GetService(“DataStoreService”)
local DataStore1 = DS:GetDataStore(“WinsSave”)
local DataStore2 = DS:GetDataStore(“DonationSave”)
local DataStore3 = DS:GetDataStore(“KillsSave”)
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new(“Folder”, player)
leaderstats.Name = “leaderstats”

local Wins = Instance.new("IntValue", leaderstats)
Wins.Name = "Ganancias"
Wins.Value = DataStore1:SetAsync(player.UserId) or 0

local Donation = Instance.new("IntValue", leaderstats)
Donation.Name = "Donacion"
Donation.Value = DataStore2:SetAsync(player.UserId) or 0

local Kills = Instance.new("IntValue", leaderstats)
Kills.Name = "Asesinatos"
Kills.Value = DataStore3:SetAsync(player.UserId) or 0

end)
game.Players.PlayerRemoving:Connect(function(player)
DataStore1:SetAsync(player.UserId, player.leaderstats.Ganancias.Value)
DataStore2:SetAsync(player.UserId, player.leaderstats.Donacion.Value)
DataStore3:SetAsync(player.UserId, player.leaderstats.Asesinatos.Value)
end)

local MPS = game:GetService(“MarketplaceService”)
MPS.ProcessReceipt = function(info)
local userid = info.PlayerId
local productid = info.ProductId
local player = game.Players:GetPlayerByUserId(userid)
local leaderstats = game.Players.leaderstats
local Donation = leaderstats.Coins
if productid == 1681905809 then
Donation.Value += 5
elseif productid == 1681906701 then
Donation.Value += 10
end
elseif productid == 1681906702 then
Donation.Value += 100
end
if productid == 1681907949 then
Donation.Value += 1000
end
elseif productid == 1681908502 then
Donation.Value += 10000
end
end

Has this finally been clarified that the product callback must return true for it to process the transaction, this has caught me out and definitely catches others out as well.

Edit: nope :smiley:

They do put a little comment that says:
image

But it really should be explained outside the code.

Hola acabo de cancelar mi juego, soy un scripter principiante asi que por lo tanto voy a hacer un obby, deseenme suerte!

Have you tried my script?

No les dije?? cancele mi juego! traduzcanlo por dios!