Current Value not changing to the SpawnPoint Value

Hi, so I’m having trouble making the Current Value changing to the SpawnPoint Value. I made a visual representation of what should happen at the bottom… Thanks for your time!

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)
				elseif tonumber(v.Name) <= player.leaderstats.Stage.Value then
						print("TEST")
					player.PlayerGui.Level.Current.Value = player.hidden.SpawnPoint.Value == tonumber(v.Name) -- this line!!!
				end
			end
		end)
	end
end

-- 214 current = 214 spawnpoint

-- 203 current = 203 spawnpoint

Couldn’t you just set it equal to the spawn point’s name?

player.PlayerGui.Level.Current.Value = tonumber(v.Name) -- this line!!!

I shouldn’t be able to do this, however I should be able to use the stage transfer feature to do this and it saves me there instead of me walking on it.

player.PlayerGui.Level.Current.Value = player.hidden.SpawnPoint.Value == tonumber(v.Name) -- this line!!!

This line would set the value to true/false, or atleast attempt to, as == returns a bool value. Is that what you want it to do?

I’ve changed the script a bit:

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)
				elseif tonumber(v.Name) <= player.leaderstats.Stage.Value then
						print("TEST")
					player.hidden.SpawnPoint.Value = player.PlayerGui.Level.Current.Value
					player.hidden.SpawnPoint.Value = tonumber(v.Name)
				end
			end
		end)
	end
end

-- 214 current = 214 spawnpoint
-- 203 current = 203 spawnpoint

What I’m trying to fix is me stepping on previous stages and it saving me there, but instead I should be able to transfer through stages (top gui) and whatever the current stage value is it should save me at that number value by equaling it to the SpawnPoint (a temp value for going to previous stages)

Can you explain what player.PlayerGui.Level.Current is for? Like what purpose does this Value object serve

It’s the value for the transfer stage, whatever the gui says is that value on the top. Its a boolvalue.

I don’t really understand but,

player.hidden.SpawnPoint.Value This is the current spawn value right?
player.leaderstats.Stage.Value and this is the actual value?

Which of those is being used to show the stage number the player is currently on?

Does the current value becomes 0 or nil?

Yep, the Stage value is the farthest stage they’ve gotten too; the SpawnPoint acts as a placeholder for other levels so you can respawn at other previous stages too.

Which stage number are you talking about? Like the GUI one or?

I’ve changed the script, look above and no it doesn’t currently.

Yeah the UI one, the number being shown on the UI

That’s a boolvalue, it’s this:
player.PlayerGui.Level.Current

that’s whats confusing me, you’re saying it’s a boolvalue but it’s showing a number?

This boolvalue is wired to the changing of the GUI, this isn’t linked to the stage number but they’re obviously related because this displays what stage they’re at. All this does is change the number for the GUI.

Yeah, that number is supposed to show what stage the player is on, so shouldn’t it change even if the player is progressing?

My point being ur not changing the text when the player is moving to the next stage

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) -- ur not changing the text of the UI
			elseif tonumber(v.Name) <= player.leaderstats.Stage.Value then
					print("TEST")
				player.hidden.SpawnPoint.Value = player.PlayerGui.Level.Current.Value -- whats the point of this?
				player.hidden.SpawnPoint.Value = tonumber(v.Name)
			end

Well it does, the GUI is fine, it’s just me staying at previous stages because currently I can walk on ones which I don’t want to be able to happen. Instead I want it so that I can only transfer through stages to change my SpawnPoint value, the placeholder for previous stages so I can go to them without respawning at my up-to-date stage. Useful for helping other players or replaying the game, etc.

I’ll show u a video between what should happen and what shouldn’t happen.

What shouldn’t happen:

What should happen:

The GUI is actually broken when I reset, I’ll fix that later.

Basically it works 50%, but the other 50% is what I need to fix which is me stepping on previous stages and it spawning me there. This should only be able to happen If I transfer through stages.

This issue is still happening, the Current Value won’t change to the SpawnPoint value. I deleted it to see if it changed anything and it didn’t. I’ve discoverd a possible lead on what may be causing this issue which is (hit.Parent) after local player = game.Players:GetPlayerFromCharacter(hit.Parent)

Here’s the update to date 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)
				elseif tonumber(v.Name) <= player.leaderstats.Stage.Value then
						print("TEST")
					player.hidden.SpawnPoint.Value = player.PlayerGui.Level.Current.Value
					player.hidden.SpawnPoint.Value = tonumber(v.Name)
				end
			end
		end)
	end
end

-- 214 current = 214 spawnpoint
-- 203 current = 203 spawnpoint

Visual representation for what I want at the bottom of the script.