The skip stage script works fine but when you’re at the last stage and buy the product it will increase your stage to a stage that doesnt exist
for example there are three stages. you get to stage 3 and stage 3 is the last stage. you buy skip stage and the leaderstats will change to stage 4 but there is not a stage 4. what can i do to fix this
also whoever fixes this for me and/or helps me gets solution guaranteed
local MarketplaceService = game:GetService("MarketplaceService")
MarketplaceService.ProcessReceipt = function(receiptInfo)
if receiptInfo.ProductId == 1135103570 then
local Player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
Player.leaderstats.Stage.Value = Player.leaderstats.Stage.Value + 1
local Character = game.Workspace:FindFirstChild(Player.Name)
local Checkpoint = game.Workspace.Checkpoints:FindFirstChild(Player.leaderstats.Stage.Value)
Character:FindFirstChild("HumanoidRootPart").CFrame = CFrame.new(Checkpoint.Position + Vector3.new(0, 5, 0), Checkpoint.Position)
Character:FindFirstChild("HumanoidRootPart").Orientation = Vector3.new(0, 0, 0)
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
There is actually two things I would HEAVILY RECOMMEND. First things first, in the button where you show the DevProduct to skip stage, check if the player is at max stage if they aren’t then show the prompt, do what @Interactivated said. The reason to do this is because you don’t just want to rob people (aka them buying a skip stage and then you don’t skip the stage because there is none, this will stop them from getting the option to purchase if it’s last stage)
i dont know how to check but i wrote this and it doesn’t work
local MarketplaceService = game:GetService("MarketplaceService")
script.Parent.MouseButton1Click:Connect(function(click)
local Player = game.Players:GetPlayerByUserId(click.PlayerId)
Player.leaderstats.Stage.Value = Player.leaderstats.Stage.Value + 1
local Character = game.Workspace:FindFirstChild(Player.Name)
local Checkpoint = game.Workspace.Checkpoints:FindFirstChild(Player.leaderstats.Stage.Value)
if Player.leaderstats.Stage.Value == 3 then
return
end
MarketplaceService:PromptProductPurchase(game.Players.LocalPlayer, 1747009608)
end)
I figured out how to stop the stage from going up like i said but i want to cancel the prompt for when i click on the button and the script is not working
-- # Services
local Players = game:GetService('Players');
local MarketplaceService = game:GetService('MarketplaceService');
-- # Product
local Product = 1135103570;
-- # Checkpoint
local Checkpoints = workspace:WaitForChild('Checkpoints');
local MaxStages = #Checkpoints:GetChildren();
-- # Functions
local PurchaseFinished = function(userId: number, productId: number, wasPurchased: boolean)
if wasPurchased == false then
return;
end;
local Player = Players:GetPlayerByUserId(userId);
if Player then
local leaderstats = Player:WaitForChild('leaderstats');
local Stage = leaderstats:WaitForChild('Stage');
if Stage.Value < MaxStages then
Stage.Value += 1
local TpCFrame = Checkpoints:FindFirstChild(Stage.Value).CFrame;
local Character = Player.Character
Character:PivotTo(TpCFrame)
end;
end;
end;
-- # Connections
MarketplaceService.PromptProductPurchaseFinished:Connect(PurchaseFinished)
Client:
-- # Services
local Players = game:GetService('Players');
local MarketplaceService = game:GetService('MarketplaceService');
-- # Player
local Player = Players.LocalPlayer;
local leaderstats = Player:WaitForChild('leaderstats');
local Stage = leaderstats:WaitForChild('Stage');
-- # Product
local Product = 1135103570;
-- # Checkpoint
local Checkpoints = workspace:WaitForChild('Checkpoints');
local MaxStages = #Checkpoints:GetChildren();
-- # UI
local Button = script.Parent;
-- # Functions
local Clicked = function()
if Stage.Value < MaxStages then
MarketplaceService:PromptProductPurchase(Player, Product);
end;
end;
-- # Connections
Button.MouseButton1Click:Connect(Clicked);