Skip Stage not working

For some reason it won’t skip the stage, it’ll prompt the purchase, I buy it, and nothing happens. It worked with my old datastore but it won’t work now.

In main script (datastore script):

local function processReceipt(receiptInfo)

	local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
	if not player then	
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end

	if receiptInfo.ProductId == 1086221671 then
		if player.leaderstats.Stage.Value < 192 then
			return Enum.ProductPurchaseDecision.NotProcessedYet
		else
			player.leaderstats.Stage.Value = player.leaderstats.Stage.Value + 1
			player:LoadCharacter()
		end
	end

	return Enum.ProductPurchaseDecision.PurchaseGranted
end

marketplaceService.ProcessReceipt = processReceipt

The script within the button to skip the stage:

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:connect(function()
	script.Parent.SkipStageScript.Click:Play()
	if player.leaderstats.Stage.Value < 192 then
		game:GetService("MarketplaceService"):PromptProductPurchase(player, 1086221671)
	else
		print("You're at the last stage.")
	end
end)

I just tested this script where I pressed a button, bought the product.

The server picked this up perfectly fine using this script and reloaded the character. However I did have to define marketplaceService as you did not define it on your server script

1 Like

It is, It’s just at the top of the script. (in the datastore script of course)

Try adding some print statements in your code for each section in the server script to identify where it is stopping. Considering it worked for me when I removed the leaderstats section (as I do not have this part to test your script) this is most likely the cause of the problem

1 Like

For some reason it won’t reach anything within the local function.

Here’s the entire script for reference:

local DataService = game:GetService("DataStoreService")
local DataStore = DataService:GetDataStore("data_01")
local marketplaceService = game:GetService("MarketplaceService")

local camera = workspace.CurrentCamera

local cpFolder = game.Workspace:WaitForChild("Checkpoints")


game.Players.PlayerAdded:Connect(function(player)
	local key = "player-" .. player.UserId

	local GetSave = DataStore:GetAsync(key) -- check for existing data 

	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"

	local hidden = Instance.new("Folder", player)
	hidden.Name = "hidden"

	local checkpoint = Instance.new("IntValue", leaderstats)
	checkpoint.Name = "Stage"

	local spawnpoint = Instance.new("IntValue", hidden)
	spawnpoint.Name = "SpawnPoint"

	if GetSave then
		checkpoint.Value = GetSave
		print("Data Loaded For " .. player.Name)
	else
		checkpoint.Value = 1
		print("New Data Created For " .. player.Name)
	end
		
	local Character = player.Character
	--local respawn2 = cpFolder[player.leaderstats.Stage.Value]
	local respawn2 = cpFolder:WaitForChild(player.leaderstats.Stage.Value)
	Character:WaitForChild("HumanoidRootPart").CFrame = respawn2.CFrame + Vector3.new(0,3,0)

	player.CharacterAdded:Connect(function(character)
		repeat wait() until workspace:FindFirstChild(character.Name)

		local player = game.Players:GetPlayerFromCharacter(character)
		local respawn = cpFolder[player.hidden.SpawnPoint.Value]

		character.HumanoidRootPart.CFrame = respawn.CFrame + Vector3.new(0,3,0)
	end)

end)

local function processReceipt(receiptInfo)
	local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
	if not player then	
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	if receiptInfo.ProductId == 1086221671 then
		if player.leaderstats.Stage.Value < 192 then
			return Enum.ProductPurchaseDecision.NotProcessedYet
		else
			player.leaderstats.Stage.Value = player.leaderstats.Stage.Value + 1
			player:LoadCharacter()
		end
	end

	return Enum.ProductPurchaseDecision.PurchaseGranted
end

marketplaceService.ProcessReceipt = processReceipt

game.Players.PlayerRemoving:Connect(function(player)
	local key = "player-" .. player.UserId
	
	DataStore:SetAsync(key, player.leaderstats.Stage.Value)
	
	print("Data Successfully Saved For " .. player.Name)
end)

Are you saying that if it’s greater than 192 they can skip the stage?

1 Like

Oh my I should of seen this earlier yes thats exactly what the problem is

That’s the less than symbol, right? I get confused sometimes but I double checked and I saw that it was. :laughing:

No worries lol, what you are saying in this line is if it’s less than 192, they can’t skip, you need to flip it to be like this:

if player.leaderstats.Stage.Value < 192 then
			player.leaderstats.Stage.Value = player.leaderstats.Stage.Value + 1
			player:LoadCharacter()
		else
			return Enum.ProductPurchaseDecision.NotProcessedYet
		end
1 Like

It’s not working, no errors. Just to make sure we’re on the right page here’s the script. I tried debugging this with print statements before, though none of them printed.

local function processReceipt(receiptInfo)
	local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
	if not player then	
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	if player.leaderstats.Stage.Value < 192 then
		player.leaderstats.Stage.Value = player.leaderstats.Stage.Value + 1
		player:LoadCharacter()
	else
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end

	return Enum.ProductPurchaseDecision.PurchaseGranted
end
1 Like

Is it not printing in your function at all?

1 Like

Yeah it seems as if nothing prints in that local function. I tried this:

local function processReceipt(receiptInfo)
	print("Hi1!")
	local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
	print("Hi2!")
	if not player then	
		print("Hi3!")
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	print("Hi4!")
	if player.leaderstats.Stage.Value < 192 then
		print("Hi!5")
		player.leaderstats.Stage.Value = player.leaderstats.Stage.Value + 1
		print("Hi!6")
		player:LoadCharacter()
		print("Hi!7")
	else
		print("Hi!8")
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end

	return Enum.ProductPurchaseDecision.PurchaseGranted
end

marketplaceService.ProcessReceipt = processReceipt

Try making a separate script in server script service as it works perfectly fine separated

https://gyazo.com/c5b179e4fde8a585c2c183ff9baa4552

1 Like

It seems that you haven’t called the function, am I correct or did you?

1 Like

I tried placing one now:

local marketplaceService = game:GetService("MarketplaceService")

local function processReceipt(receiptInfo)

	local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
	if not player then	
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	if player.leaderstats.Stage.Value < 192 then
		player.leaderstats.Stage.Value = player.leaderstats.Stage.Value + 1
		player:LoadCharacter()
	else
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end

	return Enum.ProductPurchaseDecision.PurchaseGranted
end

marketplaceService.ProcessReceipt = processReceipt
marketplaceService:Connect(processReceipt())

Got this error:
ServerScriptService.Library.Datastore:55: attempt to index nil with ‘PlayerId’ - Server - Datastore:55

Which line is having the error?

local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)

I did, still didn’t work unfortunately.

Remove the .playerid, does that fix your issue?