Skip Stage Script Not Working

So this is a simple script I put together from different scripts but it does not work. I can’t seem to get it to detect the part so it counts as a stage and then make it stop once the player reaches the last part.

Here is the main script in ServerScriptService:

MarketplaceService = game:GetService("MarketplaceService")

MarketplaceService.ProcessReceipt = function(receiptInfo)
	local players = game.Players:GetPlayers()

	local currency = "Stage"

	local var = 0

	for i=1,#players do
		if players[i].userId == receiptInfo.PlayerId then
			if receiptInfo.ProductId == 1310141274 and var == 0 then
				var = 1
				players[i].leaderstats[currency].Value = players[i].leaderstats[currency].Value + 1
				players[i].Character.Humanoid.Health = 0
				var = 0
			end
		end
	end
	return Enum.ProductPurchaseDecision.PurchaseGranted	
end

leaderstats:

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats= Instance.new("Folder")
	leaderstats.Name= ("leaderstats")
	leaderstats.Parent= player
	
	local cash= Instance.new("IntValue")
	cash.Name= ("Stage")
	cash.Parent = leaderstats
	cash.Value = 0
	
end)

And here is the dev product script:

local productId = 1310141274
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:connect(function()
	game:GetService("MarketplaceService"):PromptProductPurchase(player, productId)
end)

MarketplaceService = game:GetService("MarketplaceService")

MarketplaceService.ProcessReceipt = function(receiptInfo)
	local players = game.Players:GetPlayers()

	local currency = "Stage"

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

	if receiptInfo.ProductId == 1310141274 and player then
		player.leaderstats[currency].Value += 1
	end

	if not player then return Enum.ProductPurchaseDecision.NotProcessedYet end
	return Enum.ProductPurchaseDecision.PurchaseGranted	
end

Also, I figure that the problem is right here

Roblox is very picky about capitals, so you probably needed to capitalize the u in UserId.

Okay! Thanks, the Gui is now adding a stage every time in the leaderstats but how do I make it so each part is a checkpoint adding a stage and that the Gui correlates with that?

Sorry for the very late reply, but you should probably have your own spawning system. EX:

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local stage = plr.leaderstats.Stage.Value
		local spawn = workspace.Spawns["Stage"..stage]--just an example
		local hrp = char:WaitForChild("HumanoidRootPart")
		
		hrp.CFrame = CFrame.new(Spawn.Position + Vector3.new(0, char.Torso.Size.Y, 0))
	end)
end)

You could use PromptProductPurchaseFinished

Code example:

local MarketPlaceService = game:GetService("MarketplaceService")

local Id = 1310141274

MarketPlaceService.PromptProductPurchaseFinished:Connect(function(PlayerUserId, ProductId, succes)
	local Player = game:GetService("Players"):GetPlayerByUserId(PlayerUserId)
	local leaderstats = Player:WaitForChild("leaderstats")
	
	if ProductId == Id and succes == true then
		leaderstats.Stage.Value += 1
		Player:LoadCharacter()
	end
end)
2 Likes

*Spawn.position needed to be spawn.position :smile:
So how would I use this to refer to each part as a stage like referring to their name as 1,2,3, etc.?

The marketplace Gui worked all right before (at least so far lol), but your example works as well.

Yes, this was just an example for you to use, but with the way I had it, it would be “Stage” then the number ex: “Stage10”

1 Like

You could do like so.

Example:

local TextLabel = script.Parent 
local player = game.Players.LocalPlayer 
local leaderstats = player:WaitForChild("leaderstats") 

TextLabel.Text = "Stage: "..tostring(leaderstats.Stage.Value)

leaderstats.Stage:GetPropertyChangedSignal("Value"):Connect(function()
	TextLabel.Text = "Stage: "..tostring(leaderstats.Stage.Value)
end)
1 Like

This finally made my skip stage button work! thanks

1 Like

you’re welcome if you have any questions just hit me up!