Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is there a W006 warning in this developer-products script?

So, in this developer product purchasing server-sided handler, there is a warning on line 17 W006 warning in my script, how to get it away?

This is what the warning says:

"W006: Statement spans multiple lines; use indentation to silence"

Here is my coding:

(Also, is there something else that I did wrong with this script? , the MarketplaceService-part should fire when the player buys a dev product via my GUI)

local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")

local MarketplaceService = game:GetService("MarketplaceService")
local productId1 = 43143055 --//200 snowflakes
local productId2 = 43143018 --//500 snowflakes
local productId3 = 43143112 --//1000 snowflakes
local productId4 = 43143148 --//5000 snowflakes

--MarketplaceService.ProcessReceipt will fire when someone completes a purchase, This is how it runs!
MarketplaceService.ProcessReceipt = function(receiptInfo) 
    -- find the player based on the PlayerId in receiptInfo
    for i, player in ipairs(game.Players:GetChildren()) do
        if player.userId == receiptInfo.PlayerId then
            -- check which product was purchased
            if receiptInfo.ProductId == productId1 then 
				player.leaderstats.Snowflakes.Value = (player.leaderstats.Snowflakes.Value + 200)
			elseif receiptInfo.ProductId == productId2 then 
				player.leaderstats.Snowflakes.Value = (player.leaderstats.Snowflakes.Value + 500)
			elseif receiptInfo.ProductId == productId2 then 
				player.leaderstats.Snowflakes.Value = (player.leaderstats.Snowflakes.Value + 1000)
			elseif receiptInfo.ProductId == productId2 then 
				player.leaderstats.Snowflakes.Value = (player.leaderstats.Snowflakes.Value + 5000)
            end
        end
    end	

	-- record the transaction in a Data Store
	local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_purchase_" .. receiptInfo.ProductId
	ds:IncrementAsync(playerProductKey, 1)	
 
	-- tell ROBLOX that we have successfully handled the transaction
	return Enum.ProductPurchaseDecision.PurchaseGranted		
end

Any help is greatly appreciated!

1 comment

0

Why I hate the warning system sometimes! I'm not getting the warning on my end.

2 answers

✓ Accepted answer

Lua does not require to end statements with a semicolon, but it does not have any rules that prevent you from breaking a statement into multiple lines. This can lead to confusing bugs. Consider this code:

local text = "Name: " .. -- player.Name
-- now show this text in a UI object
UpdateLabel(label, text)

Despite the fact that UpdateLabel is separated from the local variable assignment by a comment and a new line, this code is actually equivalent to this:

local text = "Name: " .. UpdateLabel(label, text)

This code calls UpdateLabel with 'nil' instead of the text value.

The UpdateLabel call is thus flagged with the warning. Whenever you have a legitimate use for breaking statements into multiple lines, you have to indent your code to make the intent clear:

local text = "Name: " ..
    UpdateLabel(label, text) -- now the indentation structure clearly highlights the problem

This discussion is preserved as it was. New answers, comments, and votes are closed.