Checking if humanoidrootpart exists after player leaves

local humanoidRootPart= player.Character.HumanoidRootPart

humanoidRootPart.Position = "blah"
task.wait(1)
if humanoidRootPart.Parent then
humanoidRootPart.Position = "blah"
task.wait(1)
if humanoidRootPart.Parent then
humanoidRootPart.Position = "blah"

is there a way i can do something like this without having to constantly check if humanoidrootpart still exists?

(player leaves in between)

or should i just write code that doesnt effect anything when it errors

local humanoidRootPart = player.Character.HumanoidRootPart is okay. It will return an error if it does not exist. Additionally, when a player leaves, it gets “destroyed”, and unless there is some other way around that I am not aware of, you can’t check anything regarding the player instance after it leaves the game.

Try this

local humanoidRootPart = player.Character.HumanoidRootPart
local positions = { -- Add all of your positions in this table
   Vector3.new(0, 10, 0),
   Vector3.new(50, 10, 50),
   Vector3.new(-50, 10, -50),
}

for i, v in ipairs(positions) do
   if humanoidRootPart then
      humanoidRootPart.Position = v
      wait(1)
   else
      break
   end
end