Help with checkpoint system

I’m having a couple problems with my checkpoint system, and I don’t know how to solve them. Here are my scripts:
ServerScriptService:

local Players = game:GetService("Players")

local chekpointsFolder = game.Workspace.Checkpoints

Players.PlayerAdded:Connect(function(plr)
	local checkpoints = Instance.new("Folder")
	checkpoints.Name = "Checkpoints"
	checkpoints.Parent = plr
	
	local current = Instance.new("StringValue")
	current.Parent = checkpoints
	current.Name = "Current"
	
	
	plr.CharacterAdded:Connect(function(char)
		if current.Value ~= nil then
			local point = chekpointsFolder:FindFirstChild(current.Value)
			char:MoveTo(point.Position)
		end
	end)
end)

In the checkpoint:

local checkpoint = script.Parent

local Players = game:GetService("Players")

checkpoint.Touched:Connect(function(part)
	local character = part.Parent
	local plr = Players:GetPlayerFromCharacter(character)
	
	local points = plr.Checkpoints
	local current = points.Current
	
	current.Value = checkpoint.Name
end)

The first thing is that it won’t change the player’s position, and they spawn back at the start. The second issue is that I want to use collection service, but I don’t know how to do this.

you must check if the current value is above 0

if current.Value > 0 then

end

I’m using a string value, not an int value.

Can you convert your checkPointsFolder into a table like this?:

local chekpointsFolder = game.Workspace.Checkpoints:GetChildren

Once you have the folder as a table, you can call a value in the table by something like

print(chekpointsFolder[1])

Just make sure you sort the table using:

table.sort(chekpointsFolder, function(a, b) return a.Name<b.Name end)

Here is the whole test script:

local chekpointsFolder = game.Workspace.Checkpoints:GetChildren()
table.sort(chekpointsFolder, function(a, b) return a.Name<b.Name end)
for i = 1, #chekpointsFolder do
	print(chekpointsFolder[i])
end

@ayoub50 @FangScripting I did some debugging and found that the issue was with MoveTo(). It is not moving the character to the checkpoint when the player respawns. How do I fix this? I tried reinstalling studio, and it still didn’t work.

Why are you doing that Don’t use MoveTo Use this. (Set the CFrame of the HumanoidRootPart to the Check point instead.)

Player.Character.HumanoidRootPart.CFrame = YourCheckPoint.CFrame
1 Like

I tried that, and it won’t work.

try:

Player.Character.HumanoidRootPart.CFrame = CFrame.new(YourCheckPoint.Position) + Vector3.new(0,1,0)

Change

char:MoveTo(point.Position)

To

char:SetPrimaryPartCFrame(point.CFrame * CFrame.new(0 , 4 , 0))

@lilmazen1234 @msix29 @ayoub50 @FangScripting I decided to have the lava teleport you to the checkpoint and it worked. Thank you for your help.

1 Like