I’m trying to create a simple “skip stage” button for my obby game. So far, i’ve created a script that prompts a purchase on the players screen, and for 20 robux they can buy the skip stage product.
I now need help actually making a system that teleports the player to the next checkpoint when they buy the product (it currently does nothing when bought).
Not sure if this helps at all but below is my buying prompt script.
local mps = game:GetService("MarketplaceService")
script.Parent.MouseButton1Click:Connect(function()
mps:PromptProductPurchase(script.Parent.Parent.Parent.Parent, 1195878692)
end)
I’m thinking the easiest way to do this is the name the checkpoints 1-20, and create a script that checks where the player is currently on those checkpoints, and when the product is bought it shuffles them to the next stage.
^^^ thats just a thought, I have no clue how to put that as a script.
You could save an ObjectValue inside the player that points to whatever their current checkpoint is. Then whenever they purchase the product, teleport them to the next checkpoint. If you have a folder of checkpoints all named 1-20, you can do something like this:
local checkPointFolder = game.Workspace.Checkpoints
function onPurchase(playerWhoBought) --if this was fired from a remote event, you could just replace this.
local currentCheckPoint = playerWhoBought.CurrentCheckPoint.Value
local currentCheckPointNumber = currentCheckPoint.Name --let's say this is "1".
local nextPointNumber = tonumber(currentCheckPointNumber)+1
local nextCheckpoint = checkPointFolder:FindFirstChild(tostring(nextPointNumber))
--teleport the player to nextCheckpoint, and add whatever effects you want here.
end
Now this code wont work right out of the box, but it should hopefully give you and idea. I’m not going to write the teleporting stuff since I’m not sure if you want any tweens or whatever there, but this should help you find the checkpoint object.
I would recommend following this users tutorial, although you might need to follow the rest of the series too although it’s useful as it teaches you how to code this system in depth and he has multiple other videos on making the actual checkpoints, the datastore, leaderstats, rebirth system etc