Checkpoint Script Help

I am using a server script and I want it to teleport the player who died or joined the game to the first checkpoint when their “Stage” leaderboard stat becomes 1. There seems to be no error but whenever I reset my character, I am not teleported to the checkpoint. I tried to use the Humanoid Root Part to teleport the character but it said that the root part was not part of my character. The script I am using is shown below and help is appreciated.

local Players = game:GetService("Players")
local Checkpoints = game.Workspace.AllCheckpoints -- All my checkpoints

local function onPlayerJoined(Player)
	local LS = Player:WaitForChild("leaderstats")
	if LS.Stage.Value == 1 then -- Stage value
		Player.CharacterAdded:Connect(function(char)
			char:MoveTo(Checkpoints.Checkpoint1.Position)
		end)
	end
end

game.Players.PlayerAdded:Connect(onPlayerJoined)

Try using char:PivotTo! MoveTo can be obstructed, I find it behaves weird either way.

2 Likes

Whenever I reset, it does not place me in the checkpoint. Is there anything wrong with my character added function?

Where does it move you to? Just in the sky? Oh, if the stage value is not equal to one the function is not even made. Even if it is made they would teleport one checkpoint one constantly…

Maybe try to say this…

local Players = game:GetService("Players")
local Checkpoints = game.Workspace.AllCheckpoints -- All my checkpoints

local function onPlayerJoined(Player)
	local LS = Player:WaitForChild("leaderstats")
	if LS.Stage.Value == 1 then -- Stage value
		Player.CharacterAdded:Connect(function(char)

         repeat task.wait(0.1)
         until char:FindFirstChild("HumanoidRootPart")

		 char:MoveTo(Checkpoints.Checkpoint1.Position)

		end)
	end
end

game.Players.PlayerAdded:Connect(onPlayerJoined)

Try this above @FilipinoWrld

It just spawns me where I regularly spawn. Also, in the beginning, I start with my stage value as zero but when I touch my first checkpoint, it changes the value to 1. When I reset, my code does not work and I spawn where I regularly spawn. There are no errors shown.

local players = game:GetService("Players")

local spawnPoints = game.Workspace.AllCheckpoints

local function onHumanoidDied(player)
	local leaderstats = player:FindFirstChild("leaderstats")
	
	if leaderstats.Stage.Value == 1 then
		player.RespawnLocation = spawnPoints.Checkpoint1.Position
	else
		--another respawn location
	end
end

local function onPlayerAdded(player)
	local leaderstats = player:WaitForChild("leaderstats")
	
	if leaderstats.Stage.Value == 1 then
		local character = player.Character or player.CharacterAdded:Wait()
		local humanoid = character:WaitForChild("Humanoid")
		
		humanoid.Died:Connect(onHumanoidDied(player))
		
		player.RespawnLocation = spawnPoints.Checkpoint1.Position
	else
		--another respawn location
	end
end

players.PlayerAdded:Connect(onPlayerAdded)