Trying to understand line of code in checkpoint system

I used a tutorial from squidingz to make an obby checkpoint system but I don’t understand line 6. Can anyone explain that to me? Is it checking if the humanoidrootpart exists?

--Datastore variables
local DSS = game:GetService("DataStoreService")
local datastore = DSS:GetDataStore("DataStore")

function plrtostage(plr)
	repeat wait() until plr.Character.HumanoidRootPart
	
	local stagepart = game.Workspace.Checkpoints:FindFirstChild(tostring(plr.leaderstats.Checkpoint.Value))
	
	plr.Character.HumanoidRootPart.CFrame = stagepart.CFrame + Vector3.new(0,2.5,0)
end
--Leaderboard
game.Players.PlayerAdded:Connect(function(plr)
	local folder = Instance.new("Folder", plr)
	folder.Name = "leaderstats"
	
	local checkpoint = Instance.new("IntValue", folder)
	checkpoint.Name = "Checkpoint"
	
	local success, errormessage = pcall(function()
		checkpoint.Value = datastore:GetAsync(plr.UserId)
	end)
	
	if success then
		print("Success")
	else
		print("Error")
		warn(errormessage)
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local success, errormessage = pcall(function()
		datastore:SetAsync(plr.UserId, plr.leaderstats.Checkpoint.Value)
	end)
	
	if success then
		print("Saved")
	else
		print("Error")
		warn(errormessage)
	end
	
	plr.CharacterAdded:Connect(function()
		plrtostage(plr)
	end)
end)

for i,v in pairs(game.Workspace.Checkpoints:GetChildren()) do
	v.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") then
			local player = game.Players:GetPlayerFromCharacter(hit.Parent)
			
			local cnumber = tonumber(v.Name)
			
			if player.leaderstats.Checkpoint.Value < cnumber then
				player.leaderstats.Checkpoint.Value = cnumber
			end
		end
	end)
end

Line 6 inside player to stage is teleporting the player to the parts position.

Isn’t that what line 10 does? Line 6 has to be checking for something because it’s using repeat loop.

My bad, its simply waiting until it can find the humanoid root part :slight_smile:

1 Like

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