Checkpoint script doesn't work


Here is a clip of how it doesn’t work.

local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local SaveDataStore = DataStoreService:GetDataStore("SavedData")

Players.PlayerAdded:Connect(function(player)

	local Stats = Instance.new("Folder", player)
	Stats.Name = "leaderstats"

	local Stage = Instance.new("StringValue", Stats)
	Stage.Name = "Stage"
	Stage.Value = 1

	local Data = SaveDataStore:GetAsync(player.UserId)

	if Data then
		for i, stats in pairs(Stats:GetChildren()) do
			stats.Value = Data[stats.Name]  
		end
	end

	player.CharacterAdded:Connect(function(character)

		local Humanoid = character:WaitForChild("Humanoid")
		local Root = character:WaitForChild("HumanoidRootPart")


		if Root and Humanoid then
			if Stage.Value ~= 0 then
				local StagePart = workspace.Stages:FindFirstChild(Stage.Value)
				Root.CFrame = StagePart.CFrame + Vector3.new(0,5,0)     
			end 
		end 
	end)  
end)

local function SavePlayerData(player)
	local success, errormsg = pcall(function()
		local SaveData = {}
		for i, stats in pairs(player.leaderstats:GetChildren()) do
			SaveData[stats.Name] = stats.Value
		end 
		SaveDataStore:SetAsync(player.UserId,SaveData)
	end)
	if errormsg then
		warn(errormsg, script)
	end
end

Players.PlayerRemoving:Connect(function(player)
	SavePlayerData(player)
end)

game:BindToClose(function()
	for i, player in pairs(Players:GetPlayers()) do 
		SavePlayerData(player) 
	end
end)

this is the code that supposed to teleport you to the checkpoint but it doesn’t work, I fall out of the sky

I can’t notice anything wrong, you should print the values of Stage.Value , StagePart , and the resulting CFrame where the player is being teleported to.

1 Like

Hey, if you would like, you can use my checkpoint system.

1 Like

thanks so much! it worked very well

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