Little help with setting Checkpoint

Hi, developers!

I just wanted to know how do you make it work like this, if Player has touched Checkpoint1 and after touching Checkpoint2, the player can’t touch the Checkpoint1 and he doesn’t respawn on Checkpoint1 but on Checkpoint2.

Because I’ve been struggling for past few minutes and I don’t know how to make it work like this.

3 Likes

What have you got so far? That way we can help you make your code work.

Broadly speaking though, you’ll want to somehow check if the checkpoint that’s currently set is before the one that was just touched, and only set to the touched checkpoint of that’s the case.

1 Like
-- This spawns the player on the correct point 
game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character) -- this will trigger after every death
		repeat wait() until Player.Character 
		Player.Character:MoveTo(Spawns:FindFirstChild(Player.leaderstats.Stage.Value).Position)
	end)
end)


-- this handles changing checkpoints. It only allows you to change if the next checkpoint is the very next one
for _, checkpoint in pairs(Spawns:GetChildren()) do
	checkpoint.Touched:Connect(function(hit)
		local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if Player then
			local stage = Player.leaderstats.Stage.Value
			if stage + 1 == tonumber(checkpoint.Name) then
				Player.leaderstats.Stage.Value = stage + 1
			end
		end
	end)
end

Player.leaderstats.Stage.Value – This assumes you will be saving data with datastores
All the spawns should be in a folder, and for simplicity the name is just numbered in order

local Spawns = game.Workspace.Spawns
image

The problem is I’m even bad at coding, all I did was put three checkpoints and you only respawn to them when you last touched them.

And yes only set the checkpoint to the last one, and ur not able to touch checkpoint1 or 2 if you’re on checkpoint3.

In what folder do I create the script, ServerScriptData?

It doesn’t necessarily have to be, but for organizational purposes that would be best, yes.

Does the Part actually need to be a SpawnPoint or it can just be a Part?

Just a normal part, because it will bring the player to the checkpoint when their character loads.

Thanks, I’m going to try your suggestion, If something doesn’t work I’ll ask for your help again!

Little issue, after touching the “1”, I’m spawning back to “0”… @MayorGnarwhal

The easiest way in my opinion is to simply add teams to your game, and make spawnpoints correlating for each time. Turn off neutral, and when they step on the spawnplate, their team value changes. No scripting required here.

How are you tracking the player’s current stage? The code I gave assumes that you’re using leaderstats, so you may need to change the occurrences of Player.leaderstats.Stage.Value to whatever you need to access the player’s stage.

I’m planning to make over 100 stages, how do I make the Team spawnpoints from 1-10?

How do you turn off neutral? I can’t find the solution…

1 Like

In the script where you gave me, in “Player.Character:MoveTo(Spawns():FindFirstChild(Player.leaderstats.Stage.Value).Position)” and “for _, checkpoint in pairs(Spawns:GetChildren()) do” the “Spawns” is checked under with blue line, I don’t know what’s the issue

In the Spawnpoint’s properties, scroll down a little bit until you see this “teams” section.
Let’s say you make the “Level One” team. The Level One’s team color is “Maroon”. What you would do in this case is turn on AllowTeamChangeOnTouch, disable Neutral, and set the TeamColor to “Maroon”. From there, you only spawn on the plate if you are on that team, and you can join the team by touching the Spawnplate.

NOTE: Part.BrickColor =/= Part.TeamColor
Hope this helped.

Thank you for trying to help me with this issue, however I decided to use Roblox’s Checkpoint from Toolbox, and warn players to not go back to previous Checkpoints or else it’s their fault. Sorry for wasting your time, but seriously thank you for trying to help me! :slight_smile:

1 Like

No problem! Hope your game goes well!