local checkpoints = game.Workspace.Technical.CheckPoints
local checkpointval = game.Players.LocalPlayer:WaitForChild("leaderstats"):WaitForChild("checkpointch1").Value
local tempcheckpointval = game.Players.LocalPlayer:WaitForChild("leaderstats"):WaitForChild("tempch1").Value
if tempcheckpointval == 1 or checkpointval == 0 then
checkpoints.SpawnLocation.Neutral = false
checkpoints.CheckPoint1.Neutral = true
end
--checkpoint1
if checkpointval == 0 then
end
for _, checkpoints in pairs (game.Workspace.Technical.CheckPoints:GetDescendants()) do
checkpoints.Touched:Connect(function(hit)
if game.Players:FindFirstChild(hit.Parent.Name) then
if checkpointval >= tempcheckpointval then
checkpointval += 1
tempcheckpointval = 0
else
tempcheckpointval += 1
end
end
end)
end
checkpoints WILL NOT GET CHANGED because it’s the main checking thingy. temp is always set to 0 if you leave. it gets added if the player wants to start from like checkpoint 5. i keep getting this error: attempt to index nil with ‘WaitForChild’ (first line) and i don’t even know if my script would work. Please help.
The error is because the server doesn’t know who the 'LocalPlayer" is. I would take out the LocalPlayer and let the server deal with everything. Get the player the from touch event and then do the leaderstat checks.
For instance, a script like this in my checkpoint part will assign value to both leaderstats, “checkpointch1” and “tempch1” in your case. If you were to name the part “Checkpoint1” for example, on touch it would change both your leaderstat values to the “CP1” value, in this case 1. You could duplicate the part, rename it Checkpoint2 and change the first line to “local CP1 = 2” etc to create as many checkpoints as you want. If the player dies, they are respawned at the last checkpoint they touched. Modify as needed.
local CP1 = 1 --checkpoint value
local spawn = script.Parent --part that is touched
spawn.Touched:Connect(function(hit)
if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then --check for player touch
local player = game.Players:GetPlayerFromCharacter(hit.Parent) --get player from touched part
local lvl = player:WaitForChild("leaderstats").checkpointch1 --changed for your leaderstat
local templvl = player:WaitForChild("leaderstats").tempch1 --changed for your leaderstat
local checkpointData = game.ServerStorage:FindFirstChild("CheckpointData") --create checkpoint data in serverstorage
lvl.Value = CP1 --assign value to leaderstat
templvl.Value = CP1 --assign value to leaderstat
if not checkpointData then --if no data then create it
checkpointData = Instance.new("Model", game.ServerStorage)
checkpointData.Name = "CheckpointData"
end
local checkpoint = checkpointData:FindFirstChild(tostring(player.userId)) --get or create current checkpoint data
if not checkpoint then
checkpoint = Instance.new("ObjectValue", checkpointData)
checkpoint.Name = tostring(player.userId)
player.CharacterAdded:Connect(function(character) --if player dies respawn at current leaderstat checkpoint level
wait()
character:WaitForChild("HumanoidRootPart").CFrame = game.ServerStorage.CheckpointData[tostring(player.userId)].Value.CFrame + Vector3.new(0, 4, 0)
end)
end
checkpoint.Value = spawn --set checkpoint value to current checkpoint number
end
end)