Help in my script

I’m making a script to a part allways stay behind 2 studs of the player, but It’s not working, saying: attempt to index nil with ‘HumanoidRootPart’

Script:

game.Players.PlayerAdded:Connect(function(plr)
   wait(1)
   local part = game.ReplicatedStorage.Part:Clone()
   part.CanCollide = false
   part.Parent = plr.Character
   while true do
      wait()
      part.CFrame = plr.Character.HumanoidRootPart.CFrame
      part.CFrame = part.CFrame + plr.Character.HumanoidRootPart.CFrame.LookVector * -2 + Vector3.new(0,2,0)
   end
end)
game.Players.PlayerAdded:Connect(function(plr)
   wait(1)
   local part = game.ReplicatedStorage.Part:Clone()
   part.CanCollide = false
   local PlrChar=Player.Character or Player.CharacterAdded:wait()
   part.Parent = PlrChar
   while true do
      wait()
      part.CFrame = PlrChar.HumanoidRootPart.CFrame
      part.CFrame = part.CFrame + PlrChar.HumanoidRootPart.CFrame.LookVector * -2 + Vector3.new(0,2,0)
   end
end)

Worked, ty

So simple, why I never tried this before? :stuck_out_tongue:

1 Like