I have made an obby with checkpoints although sometimes my checkpoints ain't working at they put me to the start of the game

Every stage has the same script just with a different name.

1 Like
  1. it is inefficient as it is done, it can be improved
local checkpoints = script.Parent.Checkpoints

for i,v in pairs(checkpoints:GetChildren()) do
if v:IsA("BasePart") then
v.Touched:Connect(function(hit)
local plrmodel, id = hit.Parent, tonumber(v.Name);
local h, player = plrmodel:FindFirstChild("Humanoid"), game.Players:GetPlayerFromCharacter(plrmodel);

if (h) then
if (h.Health <= 0) then
local lstats = player:FindFirstChild("leaderstats")
local myvalue = lstats:FindFirstChild("Stage")
if myvalue.Value < id then
myvalue.Value = id
end
end
end)
end
end
  1. you need a localscript to do back to point
local myplr = game.Players.LocalPlayer;

local lstats = myplr:WaitForChild("leaderstats")
local stage = lstats:FindFirstChild("Stage")

local char = myplr.Character

local checkpoints = -- add the direction

function tp(v)
local item = checkpoints:FindFirstChild(tostring(v))
if (item) then
char:MoveTo(item.Position)
else
print("an error occurred while teleporting")
end
end

tp(stage.Value)
1 Like

So basically what you are saying is in the example of the 2nd checkpoint in the script which script do i put in

1 Like

you don’t have to put any script on the checkpoints, just put the checkpoints in a folder called “checkpoints”
and the script outside the “checkpoints” folder
like this:
image
also the localscript has to be in “StarterCharacterScripts”

1 Like

i don’t recommend having 100+ scripts, Try using for loops

local Players = game:GetService("Players")

for I, Parts in pairs(script.Parent:GetChildren()) do
	if tonumber(Parts.Name) ~= nil then
		if Parts:IsA("BasePart") then
			
			Parts.Touched:Connect(function(BasePart)
				local Player = Players:GetPlayerFromCharacter(BasePart.Parent)
				local Leaderstats = Player:FindFirstChild("leaderstats")
				
				if tonumber(Parts.Name) > Leaderstats.Stage.Value and Leaderstats.Stage.Value ~= tonumber(Parts.Name) and BasePart.Parent and Player ~= nil and Leaderstats then
					Leaderstats.Stage.Value = tonumber(Parts.Name)
				end
			end)
		end
	else
		
	end
end

also the explorer should be like this

ObbyCheckpoints

If you want the player to be spawning on the checkpoint the player is on

local Players = game:GetService("Players")

local Stages = game.Workspace.Stages

Players.PlayerAdded:Connect(function(Player)
	local Leaderstats = Instance.new("Folder")
	Leaderstats.Name = "leaderstats"
	Leaderstats.Parent = Player
	
	local Stage = Instance.new("IntValue")
	Stage.Name = "Stage"
	Stage.Parent = Leaderstats
	
	Player.CharacterAdded:Connect(function(Character)
		spawn(function()
			repeat task.wait() until Character.PrimaryPart ~= nil or not Character

			if Stages:FindFirstChild(Stage.Value) then
				Character:PivotTo(Stages:FindFirstChild(Stage.Value).CFrame)
			else
				warn("Stage not found")
			end
		end)
	end)
end)

1 Like

ok so ianplus just for the heads up you included 2 scripts so why is there one 1 script

1 Like