To expand more on the title, I mean how to make it so that you don't go from e.g Stage 1 to Stage 3 without touching the Stage 2 checkpoint. I am asking this because say for instance you have the flying carpet gamepass, you can fly from Stage 1 straight to the last checkpoint without having to stop at each checkpoint and I don't want that to happen.
Here is the script:
game.Players.CharacterAutoLoads = false
local dss = game:GetService("DataStoreService")
local obbyDS = dss:GetDataStore("ObbyData")
local checkpoints = workspace:WaitForChild("Checkpoints")
game.Players.PlayerAdded:Connect(function(plr)
local levelData
pcall(function()
levelData = obbyDS:GetAsync("Level-" .. plr.UserId)
if levelData then
print(levelData)
else
print(plr.Name.."has no data.")
end
end)
local ls = Instance.new("Folder")
ls.Name = "leaderstats"
ls.Parent = plr
local level = Instance.new("StringValue")
level.Name = "Level"
level.Value = levelData or "0"
level.Parent = ls
plr.CharacterAdded:Connect(function(char)
local hrp = char:WaitForChild("HumanoidRootPart")
hrp:GetPropertyChangedSignal("CFrame"):Wait()
hrp.CFrame = checkpoints[level.Value].CFrame
char.Humanoid.Died:Connect(function()
plr:LoadCharacter()
end)
char.Humanoid.Touched:Connect(function(part)
if part.Parent == checkpoints then
if part.Name ~= "End" and level.Value ~= "End" then
if part.Name > level.Value then
level.Value = part.Name
end
elseif part.Name == "End" then
level.Value = part.Name
end
end
end)
end)
plr:LoadCharacter()
end)
local function saveData(plr)
local success,errormsg = pcall(function()
obbyDS:SetAsync("Level-" .. plr.UserId, plr.leaderstats.Level.Value)
end)
if not success then
return errormsg
end
end
game.Players.PlayerRemoving:Connect(function(plr)
local errormsg = saveData(plr)
if errormsg then
warn(errormsg)
end
end)
game:BindToClose(function()
for i, plr in pairs(game.Players:GetPlayers()) do
local errormsg = saveData(plr)
if errormsg then
warn(errormsg)
end
end
wait(2)
end)

1 comment
Cant you scale the checkpoint so that you have to go through it to actually do the next stage?