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

Why does this simple math not want to work in level skipping script?

So what happens when I execute the script is the first time it will skip the first level fine. The next time though it just skips 2 levels ahead and then it just goes 3,4 ect. idk what is wrong.

local market= game.MarketplaceService
local id = 426035268

market.ProcessReceipt = function(receiptinfo) 
	for i,player in ipairs(game.Players:GetChildren())do
		if player.UserId == receiptinfo.PlayerId then
			if receiptinfo.ProductId == id then
purchasedskiplv(player)
			end
		end
	end
end

function purchasedskiplv(player)
	local plr = game.Players:FindFirstChild(player.Name)
					plr.Stats.LV.Value = plr.Stats.LV.Value + 1
end

1 answer

✓ Accepted answer

Remember, get all players with :GetPlayers() no with :GetChildren(), if :GetChildren() you can catch another instance that is not a player!

For first, you need to return Enum.ProductPurchaseDecision.PurchaseGranted on purchase ends!

If not finished purchase you need to use return Enum.ProductPurchaseDecision.NotProcessedYet

You can simple get player with game.Players:GetPlayerByUserId

Wiki page: Purchase in game/Dev products - GetPlayerByUserId

And use can use game:GetService("MarketplaceService") is better than game.MarketplaceService

Here is a example:

game:GetService("MarketPlaceService").ProcessReceipt = function(receiptinfo) 
	local player = game:GetService("Players"):GetPlayerByUserId(receiptinfo.PlayerId)
	if player then
		print("Player in game!")
		return Enum.ProductPurchaseDecision.PurchaseGranted
	else
		print("Player leaved or not found!")
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
end

Here is your script fixed:

local market = game:GetService("MarketplaceService")
local id = 426035268

function purchasedskiplv(plr)
	if plr:FindFirstChild("Stats") then
		if plr["Stats"]:FindFirstChild("LV") then
    		plr.Stats.LV.Value = plr.Stats.LV.Value + 1
		end
	end
end

market.ProcessReceipt = function(receiptinfo) 
    local player = game:GetService("Players"):GetPlayerByUserId(receiptinfo.PlayerId)
	if player and receiptinfo.ProductId == id then
		purchasedskiplv(player)
		return Enum.ProductPurchaseDecision.PurchaseGranted
	else
		print("Can not get player!")
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
end

Hope it helped :)

1 comment

0

Nice, juicy answer ;3

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