Help on Checkpoint system

Hello! I have this checkpoint system, but it doesn’t work. It doesn’t spawn the player to the designated checkpoint.

local mps = game:GetService("MarketplaceService")
local dss = game:GetService("DataStoreService")
local Folder_Stage = workspace:WaitForChild("Stages")
local MoneyStore = dss:GetDataStore("Money Data!")
local RobuxStore = dss:GetDataStore("Robux Data!")
local player = game:GetService("Players")

player.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = plr
	
	local Money = Instance.new("NumberValue")
	Money.Name = "Money"
	Money.Parent = leaderstats
	
	local Stages = Instance.new("NumberValue")
	Stages.Name = "Stages"
	Stages.Parent = leaderstats
	Stages.Value = 1
	
	local Robux = Instance.new("NumberValue")
	Robux.Name = "Robux"
	Robux.Parent = plr
	
	plr.CharacterAdded:Connect(function(char)
		wait()
		if Stages.Value > 1 then
			char:MoveTo(Folder_Stage:FindFirstChild(Stages.Value - 1).Position)
			
		end
	end)
	
end)

for i, v in pairs(Folder_Stage:GetChildren()) do
	v.Touched:Connect(function(hit)
		local hum = hit.Parent:FindFirstChild("Humanoid")
		if hum then
			local char = hit.Parent
			local plr = player:GetPlayerFromCharacter(char)
			local Stages = plr.leaderstats.Stages
			if tonumber(v.Name) == Stages.Value then
				
				Stages.Value += 1
			end
		end
		
	end)
	
end

player.PlayerRemoving:Connect(function(plr)
	-- Imma do some code later here
end)
1 Like

So what a problem can be, is that with creating things between the PlayersAdded and the CharacterAdded can make the CharacterAdded function not run, because the delay is to big. In other words, the player already loaded in when you are connecting to the event to the first time. If thats not your problem and you are certain that this event works, we need to know more informations about what Stages.Value excatly is. What I also noticed, but not maybe in relation with your problem, is that you are using WaitForChild() in a ServerScript. When you are sure that something exists, then dont use WaitForChild() on it in the Server, it will only make your Script yield and for Example can interrupt the player.PlayerAdded Event. There are better methods to detect if sth exists or not.

EDIT:
Just saw what Stages.Value is… Sry about that. Well I think that you have to convert it into a string because its a NumberValue, so tostring(Stages.Value - 1). Also, if that doesnt work, try a for loop:

for i, v in pairs(Folder_Stage:GetChildren() do
   if v.Name == tostring(Stages.Value - 1) then
       char:MoveTo(v.Position)
    end
end

Assuming that Folder_Stage contains parts…

1 Like

I’ve changed it to a INT value, and removed WaitForChild. It still doesn’t work.

local mps = game:GetService("MarketplaceService")
local dss = game:GetService("DataStoreService")
local Folder_Stage = workspace.Stages
local MoneyStore = dss:GetDataStore("Money Data!")
local RobuxStore = dss:GetDataStore("Robux Data!")
local player = game:GetService("Players")

player.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = plr
	
	local Money = Instance.new("NumberValue")
	Money.Name = "Money"
	Money.Parent = leaderstats
	
	local Stages = Instance.new("IntValue")
	Stages.Name = "Stages"
	Stages.Parent = leaderstats
	Stages.Value = 1
	
	local Robux = Instance.new("NumberValue")
	Robux.Name = "Robux"
	Robux.Parent = plr
	
	plr.CharacterAdded:Connect(function(char)
		wait()
		if Stages.Value > 1 then
			char:MoveTo(Folder_Stage:FindFirstChild(Stages.Value - 1).Position)
			
		end
	end)
	
end)

for i, v in pairs(Folder_Stage:GetChildren()) do
	v.Touched:Connect(function(hit)
		local hum = hit.Parent:FindFirstChild("Humanoid")
		if hum then
			local char = hit.Parent
			local plr = player:GetPlayerFromCharacter(char)
			local Stages = plr.leaderstats.Stages
			if tonumber(v.Name) == Stages.Value then
				
				Stages.Value += 1
			end
		end
		
	end)
	
end

player.PlayerRemoving:Connect(function(plr)
	
end)

Stages

Pic of the folder

player.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = plr
	
	local Money = Instance.new("NumberValue")
	Money.Name = "Money"
	Money.Parent = leaderstats
	
	local Stages = Instance.new("NumberValue")
	Stages.Name = "Stages"
	Stages.Parent = leaderstats
	Stages.Value = 1
	
	local Robux = Instance.new("NumberValue")
	Robux.Name = "Robux"
	Robux.Parent = plr
	
	plr.CharacterAdded:Connect(function(char)
		wait()
        print("Character Added!")
		if Stages.Value > 1 then
            local value = Stages.Value - 1
			char:MoveTo(Folder_Stage:FindFirstChild(value).Position)
            print("Moving char")			
		end
	end)
	
end)

Try that and tell if the prints printed

EDIT: Why are you substracting Stages.Value - 1?

This doesn’t print.

Subracting 1 so they don’t skip stages.

Hello!

I recently made a working checkpoint system with an option to skip stages. I can provide you with the code and modify it to fit your game, if you like.

That’ll be great! Can I see the checkpoint system?

1 Like

If theres no error in the output from FindFirstChild, your problem is the if statement

Sure! I removed everything from the skip stage feature but let me know if you would like that as well.

local Checkpoints = game.Workspace:WaitForChild("Checkpoints")

game.Players.PlayerAdded:Connect(function(Player)
	local leaderstats = Instance.new("Folder", Player)
	leaderstats.Name = "leaderstats"
	
	local Stage = Instance.new("IntValue", leaderstats)
	Stage.Name = "Stage"
	Stage.Value = 0
	
	Player.CharacterAdded:Connect(function(Character)
		local Humanoid = Character:WaitForChild("Humanoid")
		task.wait()
		Character:MoveTo(Checkpoints[Stage.Value].Position)
		
		Humanoid.Touched:Connect(function(hit)
			if hit.Parent == Checkpoints then
				if tonumber(hit.Name) == Stage.Value + 1 then
					Stage.Value += 1
				end
			end
		end)
	end)
end)

Hey sorry for responding late, roblox devforum crashed for me for a bit. I’ll go check it out!

2 Likes

I finally figured it out!

local mps = game:GetService("MarketplaceService")
local dss = game:GetService("DataStoreService")
local Stage_Store =dss:GetDataStore("Stage Data!")
local MoneyStore = dss:GetDataStore("Money Data!")
local RobuxStore = dss:GetDataStore("Robux Data!")
local player = game:GetService("Players")
local Folder_Stage = workspace:WaitForChild("Stages")

function PlrToStage(plr)
	repeat wait() until plr.Character.HumanoidRootPart
	
	local StagePart = Folder_Stage:FindFirstChild(tostring(plr.leaderstats.Stage.Value))
	
	plr.Character.HumanoidRootPart.CFrame = StagePart.CFrame + Vector3.new(0,2.5,0) -- CFrame is NIL
	
end


player.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = plr
	
	local Money = Instance.new("NumberValue")
	Money.Name = "Money"
	Money.Parent = leaderstats
	
	local Stages = Instance.new("IntValue")
	Stages.Name = "Stage"
	Stages.Parent = leaderstats
	
	local Robux = Instance.new("NumberValue")
	Robux.Name = "Robux"
	Robux.Parent = plr
	
	local Success, errormsg = pcall(function()
		Stages.Value = Stage_Store:GetAsync(plr.UserId)
	end)
	
	if Success then
		print("Success!")
	else
		warn(errormsg)
		
		
	end	
	
	if plr.Character then
		PlrToStage(plr)
	end
	
	plr.CharacterAdded:Connect(function()
		PlrToStage(plr)
	end)
end)



player.PlayerRemoving:Connect(function(plr)
	local success, errormsg = pcall(function()
		Stage_Store:SetAsync(plr.UserId, plr.leaderstats.Stage.Value)
		
	end)
	
	if success then
		print("Success")
		
		else
		warn(errormsg)
		
	end
end)

for i, v in pairs(Folder_Stage:GetChildren()) do
	v.Touched:Connect(function(hit)
		local hum = hit.Parent:FindFirstChild("Humanoid")
		
		if hum then
			local char = player:GetPlayerFromCharacter(hit.Parent)
			
			local Stage_Num = tonumber(v.Name)
			
			if char.leaderstats.Stage.Value < Stage_Num then
				char.leaderstats.Stage.Value = Stage_Num
				
			end
		end
		
	end)
	
end
2 Likes

Great job! Did my code help at all?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.