Issue with it not teleporting me to the correct stage

Okay so I’m having an issue where I have a boolvalue named SpawnPoint, and it’s suppose to teleport when I die at that specific stage however it hasn’t been doing that. For some reason it teleports to the stage where I spawn at in the beginning.

Here’s the script that’s suppose to teleport me to that specific stage (near the bottom):

local DataService = game:GetService("DataStoreService")
local DataStore = DataService:GetDataStore("data_01")

local camera = workspace.CurrentCamera

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

game.Players.PlayerAdded:Connect(function(player)
	local key = "player-" .. player.UserId

	local GetSave = DataStore:GetAsync(key) -- check for existing data 

	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"

	local hidden = Instance.new("Folder", player)
	hidden.Name = "hidden"

	local checkpoint = Instance.new("IntValue", leaderstats)
	checkpoint.Name = "Stage"

	local spawnpoint = Instance.new("IntValue", hidden)
	spawnpoint.Name = "SpawnPoint"

	if GetSave then
		checkpoint.Value = GetSave
		print("Data Loaded For " .. player.Name)
	else
		checkpoint.Value = 1
		print("New Data Created For " .. player.Name)
	end

	player.hidden.SpawnPoint.Value = player.leaderstats.Stage.Value

	local character = player.Character or player.CharacterAdded:Wait()
	local respawn2 = cpFolder:WaitForChild(player.leaderstats.Stage.Value)
	character:WaitForChild("HumanoidRootPart").CFrame = respawn2.CFrame + Vector3.new(0,3,0)

	player.CharacterAdded:Connect(function(character)

		repeat wait() until workspace:FindFirstChild(character.Name)
		local player = game.Players:GetPlayerFromCharacter(character)
		local respawn = cpFolder[player.hidden.SpawnPoint.Value]

		character.HumanoidRootPart.CFrame = respawn.CFrame + Vector3.new(0,3,0)
	end)

end)

As you can see it’s suppose to teleport me when I die because of this:


	player.CharacterAdded:Connect(function(character)

		repeat wait() until workspace:FindFirstChild(character.Name)
		local player = game.Players:GetPlayerFromCharacter(character)
		local respawn = cpFolder[player.hidden.SpawnPoint.Value]

		character.HumanoidRootPart.CFrame = respawn.CFrame + Vector3.new(0,3,0)

Here are other scripts that could possibly be affecting this making it not work maybe? Checkpoint Handler script:

local checkpoints = workspace:WaitForChild("Checkpoints")

for i,v in pairs(checkpoints:GetChildren()) do
	if v:IsA("BasePart") then
		v.Touched:Connect(function(hit)
			if hit.Parent:FindFirstChild("Humanoid") then
				local player = game.Players:GetPlayerFromCharacter(hit.Parent)
				if tonumber(v.Name) == player.leaderstats.Stage.Value + 1 then --Checks if the new checkpoint is only increasing by 1.
					player.leaderstats.Stage.Value = tonumber(v.Name)
				if player.hidden.SpawnPoint.Value == player.PlayerGui.Level.Current.Value then
						player.hidden.SpawnPoint.Value = tonumber(v.Name)
					end
				end
			end
		end)
	end
end

GUI handler:

local UI = script.Parent

local player = game.Players.LocalPlayer

local checkpoints = workspace:WaitForChild("Checkpoints")

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Teleport = ReplicatedStorage:WaitForChild("Teleport")

local Counter = UI:WaitForChild("Counter")
local Level = Counter:WaitForChild("Level")
local Previous = UI:WaitForChild("Previous")
local Next = UI:WaitForChild("Next")
local Previous1 = UI:WaitForChild("Previous1")
local Next1 = UI:WaitForChild("Next1")
local CurrentValue = UI:WaitForChild("Current")

local function previousLevel()
	script.Parent.Handler.Click:Play()
	if CurrentValue.Value ~= 1 then
		CurrentValue.Value = CurrentValue.Value - 1
		player.hidden.SpawnPoint.Value = player.hidden.SpawnPoint.Value - 1
		Level.Text = CurrentValue.Value
		-- teleport
		Teleport:FireServer(checkpoints:FindFirstChild(tostring(CurrentValue.Value)))
	end
end

local function previousLevel2()
	script.Parent.Handler.Click:Play()
	if CurrentValue.Value >= 11 then
		CurrentValue.Value = CurrentValue.Value - 10
		player.hidden.SpawnPoint.Value = player.hidden.SpawnPoint.Value - 10
		Level.Text = CurrentValue.Value
		-- teleport
		Teleport:FireServer(checkpoints:FindFirstChild(tostring(CurrentValue.Value)))
	end
end

local function nextLevel()
	script.Parent.Handler.Click:Play()
	if (CurrentValue.Value + 1) <= player.leaderstats.Stage.Value then
		CurrentValue.Value = CurrentValue.Value + 1
		player.hidden.SpawnPoint.Value = player.hidden.SpawnPoint.Value + 1
		Level.Text = CurrentValue.Value
		-- teleport
		Teleport:FireServer(checkpoints:FindFirstChild(tostring(CurrentValue.Value)))
	end
end

local function nextLevel2()
	script.Parent.Handler.Click:Play()
	if (CurrentValue.Value + 10) <= player.leaderstats.Stage.Value then
		CurrentValue.Value = CurrentValue.Value + 10
		player.hidden.SpawnPoint.Value = player.hidden.SpawnPoint.Value + 10
		Level.Text = CurrentValue.Value
		-- teleport
		Teleport:FireServer(checkpoints:FindFirstChild(tostring(CurrentValue.Value)))
	end
end


Previous.MouseButton1Click:Connect(function()
	previousLevel()
end)

Previous1.MouseButton1Click:Connect(function()
	previousLevel2()
	
end)

Next.MouseButton1Click:Connect(function()
	nextLevel()

end)

Next1.MouseButton1Click:Connect(function()
	nextLevel2()
	
end)

CurrentValue.Value = player:WaitForChild("leaderstats").Stage.Value
Level.Text = CurrentValue.Value

player.leaderstats.Stage:GetPropertyChangedSignal("Value"):Connect(function()
	CurrentValue.Value = player.leaderstats.Stage.Value
	Level.Text = CurrentValue.Value
end)