How to make the character spawn at the right checkpoint

im using the script @Zombiefin suggested, which is this:

script.Parent.Touched:Connect(function(hit)
local hum = hit.Parent:FindFirstChild(“Humanoid”)

if hum then
	local player = game.Players:FindFirstChild(hum.Parent.Name)
	
	if player then
		local stats = player:FindFirstChild("leaderstats")
		
		if stats then
			local checkp = stats:FindFirstChild("Checkpoint")
			
			if checkp then
				if checkp.Value == (script.Parent.Name - 1) then
					checkp.Value = checkp.Value + 1
				end
			end
		end
	end
end

end)

do you know how to add a [ if leaderstats “checkpoints” = 1 set spawn at checkpoint 1 ] line to this?

Yes i have
30charsssssssssssss

This should be working then, have you checked the output?

Checkpoint.rbxl (24.7 KB)
I was messing around with checkpoints, take a look, this might help with what you are trying to do

AdminScript (For Testing, /sl username level)
ServerScriptService>AdminScript

local Admins = {""}
local Module = require(game.ServerScriptService.CheckpointModule)
game.Players.PlayerAdded:Connect(function(Player)
	if table.find(Admins, Player.Name) then
		Player.Chatted:Connect(function(msg)
			if msg:lower():sub(1,9) == "/setlevel" or msg:lower():sub(1,3) == "/sl" then
				local TargetName = string.split(msg, " ")[2]
				local TargetLevel = string.split(msg, " ")[3]
				for i,v in pairs(game.Players:GetPlayers()) do
					if v.Name:lower() == TargetName:lower() then
						Module.SetPlayerLevel(v, tonumber(TargetLevel))
					end
				end
			end
		end)
	end
end)

ModuleScript For Checkpoints:
ServerScriptService>CheckpointModule

local module = {}


local Levels = {}
local CanGoDownInLevels = false
local RespawnDelay = 2


function module.GetPartFromLevel(Level)
	for i,v in pairs(Levels) do
		if v[2] == Level then
			return v[1]
		end
	end
end


function module.SetPlayerLevel(Player, NewLevel)
	Player:WaitForChild("leaderstats"):WaitForChild("Level").Value = NewLevel
end


function module.GetPlayerLevel(Player, NewLevel)
	return Player:WaitForChild("leaderstats"):WaitForChild("Level").Value
end


local Initiated = false
function module.AddLevel(Part, Level)
	if not Initiated then
		Initiated = true
		game.Players.CharacterAutoLoads = false
		game.Players.PlayerAdded:Connect(function(NewPlayer)
			local Folder = Instance.new("Folder", NewPlayer)
			Folder.Name = "leaderstats"
			local LevelValue = Instance.new("IntValue", Folder)
			LevelValue.Name = "Level"
			LevelValue.Value = 1
			NewPlayer.CharacterAdded:Connect(function(NewCharacter)
				repeat
					wait(0.01)
				until
					NewCharacter:FindFirstChild("HumanoidRootPart") ~= nil
				
				NewCharacter.HumanoidRootPart.CFrame = module.GetPartFromLevel(LevelValue.Value).CFrame + Vector3.new(0,5,0)
				DiedConnection = NewCharacter:WaitForChild("Humanoid").Died:Connect(function()
					wait(RespawnDelay)
					NewPlayer:LoadCharacter()
					DiedConnection:Disconnect()
				end)
			end)
			NewPlayer:LoadCharacter()
		end)
	end
	local Success = false
	local PartIsInTable = false
	local LevelIsInTable = false
	for i,v in pairs(Levels) do
		if v[1] == Part then
			PartIsInTable = true
		end
		if v[2] == Level then
			LevelIsInTable = true
		end
	end
	if not PartIsInTable and not LevelIsInTable then
		if Part:FindFirstChild("LevelGui") ~= nil then
			Part["LevelGui"]["LevelText"].Text = Level
		end
		table.insert(Levels, {Part, Level})
		Success = true
	end
	if Success then
		Part.Touched:Connect(function(hit)
			local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
			if Player ~= nil then
				--local PlayerCharacter = Player.Character or Player.CharacterAdded:Wait()
				if CanGoDownInLevels then
					module.SetPlayerLevel(Player, Level)
				else
					if module.GetPlayerLevel(Player) < Level then
						module.SetPlayerLevel(Player, Level)
					end
				end
			end
		end)
	end
end


function module.ClearLevels()
	Levels = {}
end


function module.GetLevels()
	return Levels
end


function module.RemoveLevelByLevel(Level)
	for i,v in pairs(Levels) do
		if v[2] == Level then
			table.remove(Levels, i)
		end
	end
end


function module.RemoveLevelByPart(Part)
	for i,v in pairs(Levels) do
		if v[1] == Part then
			table.remove(Levels, i)
		end
	end
end


return module

Script to add the checkpoints into the module:
ServerScriptService>CheckpointModule>Script

local Module = require(script.Parent)
for i,v in pairs(workspace.Checkpoints:GetChildren()) do
	Module.AddLevel(v, v:WaitForChild("Level").Value)
end

Edit:
Since you are using the names of the part instead of the intvalue:

local Module = require(script.Parent)
for i,v in pairs(workspace.Checkpoints:GetChildren()) do
	Module.AddLevel(v, tonumber(v.Name))
end
1 Like


This is what is happening…
output shows nothing wrong.
Edit: yes i am streaming… ._.

So if i duplicate it would i have to change any scripting?
or just the intvalue?

I think I know whats wrong, is the spawn point where you join the game ticked “Neutral”?

Try making a vector3 value, and when the player touches the “checkpoint part”, you save the position of that part to the vector3 value.