Checkpoint loading system

AHHAHAAHhahahahahahahhHAHAHAHHA OLD TOPIC did you think you could actually read these cringe scripts? lmao.

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.

OH YEAH I FORGOT I AM SO DUMB LOL. I’m not sure if the rest of the script will work though.

Maybe there is a reason but what is the purpose of having a checkpoint leaderstat and a tempcheckpoint leaderstat?

checkpoints are the checkpoints you’ve reached and temp is a value only changed when you load at a certain checkpoint.

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)