Trying to make checkpoint script using enabled property

I’m trying to make a checkpoint script for my obby and the scripts i’ve come across have seemed hard to understand so i’m trying to make a script where when you touch a checkpoint, all checkpoints are unenabled but that one. It hasn’t worked and I haven’t gotten anything in the output.

local checkpoints = workspace.Checkpoints:GetChildren()

local valueName = "Checkpoint"

game.Players.PlayerAdded:Connect(function(plr)
	local folder = Instance.new("Folder", plr)
	folder.Name = "leaderstats"

	local Value = Instance.new("IntValue", folder)
	Value.Name = valueName
	Value.Value = 1
	
	for i,v in pairs(checkpoints) do
		v.Touched:Connect(function()
			if tonumber(v.Name) >= Value.Value then
				checkpoints.Enabled = false
				task.wait()
				v.Enabled = true
			end
		end)
	end
end)
1 Like

Try this:

local checkpoints = workspace.Checkpoints:GetChildren()

local valueName = "Checkpoint"

game.Players.PlayerAdded:Connect(function(plr)
	local folder = Instance.new("Folder", plr)
	folder.Name = "leaderstats"

	local Value = Instance.new("IntValue", folder)
	Value.Name = valueName
	Value.Value = 1
	
	for i,v in pairs(checkpoints) do
		v.Touched:Connect(function()
			if tonumber(v.Name) >= Value.Value then
				v.Enabled = false
				task.wait()
				v.Enabled = true
			end
		end)
	end
end)
1 Like

It sadly doesn’t work, the enabled property probably isn’t meant for checkpoints.

My first reply, woohoo.
I’ve tried to make a checkpoint system before using something pretty similar, but nothing i did would make the enabled property work for checkpoints. I would recommend spawning the player on a spawnpoint that is distant from the checkpoints, and instead of doing enabled stuff, use something similar to your enabling function to check if the checkpoint’s number corresponds to their score, then teleport them to it’s position (plus a bit of Y to make them teleport above it and not into it)

I’m not sure how to write the code boxes in the forum yet so this is all i can really give. Good luck!

1 Like

I believe your solution would look something like this;

local checkpoints = workspace.Checkpoints:GetChildren()

local valueName = "Checkpoint"

game.Players.PlayerAdded:Connect(function(plr)
	local folder = Instance.new("Folder", plr)
	folder.Name = "leaderstats"

	local Value = Instance.new("IntValue", folder)
	Value.Name = valueName
	Value.Value = 1
	
	for i,v in pairs(checkpoints) do
		v.Touched:Connect(function()
			if tonumber(v.Name) >= Value.Value then
				
			end
		end)
	end
    plr.CharacterAdded:Connect(function(chr)
        chr:MoveTo(checkpoint[tostring(Value.Value)].Position + Vector3.new(0,2,0))
    end)
end)
2 Likes

Why are you trying to make every other checkpoint un-enabled instead of that one? This seems like a case of: https://xyproblem.info/

If you want to make a checkpoint system, just set the .RespawnLocation and make sure each SpawnLocation has Neutral set to true.

Code:

--//Services
local Players = game:GetService("Players")

--//Variables
local Checkpoints = workspace.Checkpoints

--//Functions
Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local playerCheckpoint = Instance.new("IntValue")
	playerCheckpoint.Name = "Checkpoint"
	playerCheckpoint.Value = 1
	playerCheckpoint.Parent = leaderstats
	
	for i, checkpoint in Checkpoints:GetChildren() do
		local stageValue = tonumber(checkpoint.Name)

		checkpoint.Touched:Connect(function()
			if stageValue == playerCheckpoint.Value + 1 then
				playerCheckpoint.Value += 1
				player.RespawnLocation = checkpoint
			end
		end)
	end
	
	player.RespawnLocation = Checkpoints:WaitForChild("1")
end)
2 Likes

This is a flawed design that will never work.

  • Multiplayer games: the other players will spawn on the wrong points
  • Spawn locations are random, so you must disable the previous points after being touched.
1 Like

OP already uses SpawnLocations so you can just set player.RespawnLocation instead of implementing a teleport on spawn system.

2 Likes

Ah, I was not aware of the player.RespawnLocation property. Thank you for improving upon my script!

2 Likes

Just add ‘’’ in start and end of code.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.