How to make pets to follow me?

Will I have to always loop my CFrames?

while wait(1) do
local player = script.Parent.Owner.Value
if workspace[player] then
local character = workspace[player]
if(script.Parent.PetMain.Position - character.HumanoidRootPart.Position).Magnitude > 25 then
script.Parent.PetMain.CFrame = -- How will I get my back CFrame to rotate it to there?
end
end
end)
1 Like

use body movers

you can use BodyPosition to position the object

and BodyGyro to rotate it

local pet -- pet mesh / part
local character -- character model

function attach(character, pet)
  local root = character:WaitForChild("HumanoidRootPart")
  local position = root.CFrame
  pet.CFrame = position
  pet.Anchored = true
  local weld = Instance.new('WeldConstraint', pet)
  weld.Name = 'pet weld'
  weld.Part0 = pet
  weld.Part1 = root
  pet.Anchored = false
  return weld
end

attach(character, pet)

method i used when i was 13 years old

But then it will be in my HumanoidRootPart

-HumanoidRootPart.CFrame.LookVector

Represents the direction of the character’s negative lookvector (backvector).

You should CFrame the pet on the client. I am assuming you’re doing it on the server as you aren’t defining player as Players.LocalPlayer. It’s unnecessary doing it on the server.

There is a great module by @LuaBearyGood that has code you can take from, you can find it here!

1 Like