I don’t know if you want a player to touch the checkpoint, so you can just do it with a Touched event.
Part.Touched:Connect(function(hit) --
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if player then
player.RespawnLocation = Part
end
end)
Make sure the class name of the part is RespawnLocation.
Maybe, you can rename each checkpoint’s name to their stage number. But this time, you would use for loop. It would be easier than the previous one.
for i, v in ipairs(workspace.CheckpointFolder:GetChildren()) do
v.Touched:Connect(function(hit)
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if tonumber(v.Name) == (player.leaderstats.Stage.Value + 1) then
if player then
player.leaderstats.Stage.Value = tonumber(v.Name)
player.RespawnLocation = v
end
end
end)
end
I just gave an example of how you can increase the value & specify a new respawn location. You can change the name --CheckpointFolder, leaderstats or stage- whatever you want to.
@MasterObstacles Thanks, I just noticed that I wrote them wrong.
Try making teams and with each team is a spawn location. When the player touches the spawn location, they automatically change teams. When this happens, every time they die, they will respawn at the spawn location they are required to spawn at.
I believe you can also save the team/team color they are at with datastore, but I have never tried.
Just make sure the player variable is above the if statement or you will get the error “attempt to index nil with leaderstats”
for i, v in ipairs(workspace.CheckpointFolder:GetChildren()) do
v.Touched:Connect(function(hit)
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if tonumber(v.Name) == (player.leaderstats.Stage.Value + 1) then
if player then
player.leaderstats.Stage.Value = tonumber(v.Name)
player.RespawnLocation = v
end
end
end)
end