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)
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)
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!
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)
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)