How do i function this obby skip stage button

i dont know how to function this skip stage button
Capture
i just have this script in the button:
script.Parent.MouseButton1Click:Connect(function()

local id = 955366611

local plr = game.Players.LocalPlayer

local MP = game:GetService(“MarketplaceService”)

MP:PromptProductPurchase(plr,id)

end)

and this is how my stage script:
local Stages = workspace:WaitForChild(“Stages”)

for i,Stage in pairs(Stages:GetChildren()) do

Stage.Touched:Connect(function(touch)
		
	local humanoid
	
	if touch.Parent:FindFirstChild("Humanoid") then
		
		humanoid = touch.Parent.Humanoid
	end
	
	if touch.Parent and touch.Parent.Parent:FindFirstChild("Humanoid") then
		
		humanoid = touch.Parent.Parent.Humanoid
	end
	
	if humanoid then
		
		local player = game.Players:GetPlayerFromCharacter(humanoid.Parent)
		
		local PlayerStage = player.leaderstats.Stage.Value
		
		if tonumber(Stage.Name) == PlayerStage + 1 then
			
			player.leaderstats.Stage.Value = player.leaderstats.Stage.Value + 1
		
		elseif tonumber(Stage.Name) > PlayerStage + 1 then
			
			humanoid.Health = 0
		end
	end
end)

end

i wanna if a player click it ,then it will skip a stage .

1 Like

ID local = 955366611
is this a gamepass?

i changed to devs product -----------------------------------

You need to make a handler for the dev products.

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
MarketplaceService.ProcessReceipt = function(receiptInfo)
	local productId = receiptInfo.ProductId
	local playerId = receiptInfo.PlayerId
	local player = getPlayerFromId(playerId)
    if productId == 955366611 then
        player.leaderstats.Stage.Value = player.leaderstats.Stage.Value + 1
    end
end

Put it in ServerScriptService.

this just +1 for the stage but i want the person teleport to the stage too

If there’s a script or something which spawns the player somewhere depending on their stage, Player:LoadCharacter() will do.

For your normal stage system, did you use a team system or a custom system?

Edit: The solution provided in the post linked here is the answer. To teleport them to the stage, add a player:LoadCharacter() to get the final code.

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
MarketplaceService.ProcessReceipt = function(receiptInfo)
	local productId = receiptInfo.ProductId
    local playerId = receiptInfo.PlayerId
    local player = game.Players:getPlayerFromUserId(playerId)
    if productId == (productidhere) then
        player.leaderstats.Stage.Value = player.leaderstats.Stage.Value + 1
        player:LoadCharacter()
    end
end
player:LoadCharacter()

after you add to their stage.

955366611 is not an gamepass

and you need add

player:LoadCharacter()

You could make an teleport function and teleport the player to the next spawn.

1 Like

is there something spell wrong with getPlayerFromId

Use the :MoveTo() function to teleport the players character to the next spawn.

touch.Parent:MoveTo( write here the spawn point player should move to, and type ".Position" after it.)

Oh yeah, you have to make that GetPlayerByUserId. Check out my edited code in the previous post, I’ve edited it so it should work now.

replace my script?
its said Can only register ProcessReciept callback on server

MarketplaceService = game:GetService(“MarketplaceService”)

MarketplaceService.ProcessReceipt = function(receiptInfo)

local players = game.Players:GetPlayers()

local done = 0

for i=1, #players do
	if players[i].userId ==receiptInfo.PlayerId then
		if receiptInfo.ProductId == 957094505 and done == 0 then
			done = 1
			players[i].leaderstats.Stage.Value = players[i].leaderstats.Stage.Value + 1
			done = 0
			players[i]:LoadCharacter()
		end
	end
end

return Enum.ProductPurchaseDecision.PurchaseGranted	

end

The code has to be on server side.

what do you mean? mine is not working?

server side?______________________________

Server script in ServerScriptService.