Im new to scripting and I'm trying to make an obby. I've found plenty of fms for an obby that saves your checkpoints with datastore/leaderstats and plenty of fms for an obby that lets you skip stages with devproducts. But I have yet to find one with both.
So basically I could use some help. Here are my scripts so far.
obbyhandler:
local obbyStages = workspace:WaitForChild("Checkpoints")
for _,stage in pairs(obbyStages:GetChildren()) do
stage.Touched:connect(function(hit)
local hum
if hit.Parent:FindFirstChild("Humanoid") then
hum = hit.Parent.Humanoid
end
if hit.Parent and hit.Parent.Parent:FindFirstChild("Humanoid") then
hum = hit.Parent.Parent.Humanoid
end
if hum then
local plr = game.Players:GetPlayerFromCharacter(hum.Parent)
local plrStage = plr.leaderstats.Stage.Value
if tonumber(stage.Name) == plrStage + 1 then
plr.leaderstats.Stage.Value = plr.leaderstats.Stage.Value + 1
elseif tonumber(stage.Name) > plrStage + 1 then
hum.Health = 0
end
end
end)
end
playerhandler:
local player = game:GetService("Players")
local dataStoreService = game:GetService("DataStoreService")
local saveDataStore = dataStoreService:GetDataStore("SaveDataTest")
local function savePlrData(plr)
local success,err = pcall(function()
local saveData = {}
for _,stat in pairs(plr.leaderstats:GetChildren())do
saveData[stat.Name] = stat.Value
end
saveDataStore:SetAsync(plr.UserId,saveData)
end)
if not success then return err end
end
player.PlayerAdded:connect(function(plr)
local stats = Instance.new("Folder")
stats.Name = "leaderstats"
stats.Parent = plr
local stage = Instance.new("IntValue")
stage.Name = "Stage"
stage.Parent = stats
local data = saveDataStore:GetAsync(plr.UserId)
if data then
print(data.Stage)
for _,stat in pairs(stats:GetChildren()) do
stat.Value = data[stat.Name]
end
else
print(plr.Name .. " has no data")
end
plr.CharacterAdded:connect(function(char)
local humanoid,hrp = char:WaitForChild("Humanoid"),char:WaitForChild("HumanoidRootPart")
wait()
if humanoid and hrp then
if stage.Value ~= 0 then
local part = workspace.Checkpoints:FindFirstChild(stage.Value)
hrp.CFrame = part.CFrame + Vector3.new(0,1,0)
end
end
end)
end)
player.PlayerRemoving:connect(function(plr)
local err = savePlrData(plr)
if err then print(err) end
end)
game:BindToClose(function()
for _,plr in pairs(player:GetPlayers()) do
local err = savePlrData(plr)
if err then print(err) end
end
wait(2)
end)
All of that is for the handling and datastore (and it works great). I just don't know how to incorporate a skip stage feature. I've already got this for a button that allows purchasing a skip.
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local productID = 1049036924
script.Parent.MouseButton1Click:Connect(function(promptPurchase)
local player = Players.LocalPlayer
MarketplaceService:PromptProductPurchase(player, productID)
end)
Finally, I have used numerous tutorials but haven't figured out how to do it. The closest I got was the devproduct purchase prompt appearing, me buying it, nothing happening except the output telling me the datastore has too many requests.
That's all folks. I know its a lot (at least i think it is) so i cant say I expect a lot of help, but a forum post is worth a shot.

2 comments
correct me if im wrong (because i didnt read 70% of the stuff) but on the last code you are just showing the buy screen, theres no code for it that checks if it was successful?
yea, thats just what I have for a prompt which works. Ive tried things that check if it was a successful purchase to no avail, so i didnt want to put in a part that doesnt work