What is a better way to handle making a pet follow the player?

I wrote a quite basic way to make a pet follow the player around. The only issue is I’m worried this method is bad for performance. Are there any better ways? I feel like creating and running a new tween every second is not the best idea…

while true do
	TweenService:Create(exterior, info, {CFrame = player.Character.HumanoidRootPart.CFrame * orbPositionOffset}):Play()
	task.wait(1)
end

You could have AlignPosition and AlignOrientation instead. What they basically do is try and match the position and orientation of two attachments. Using this reduces lag as it’s more performance-friendly. Here’s an example

local char = game.Players.LocalPlayer.Character
local pet = — Your pet here
pet.Parent = char
local AO = Instance.new(“AlignOrientation”,pet)
local AP = Instance.new(“AlignPosition”,pet)
local A0 = Instance.new(“Attachment”,pet)
A0.Visible = false
local A1 = Instance.new(“Attachment”,char.HumanoidRootPart)
A1.Visible = false
A1.Position = Vector3.new(1,1,0) + pet.PrimaryPart.Size
AO.Attachment0 = A0
AO.Attachment1 = A1
AP.Attachment0 = A0
AP.Attachment1 = A1

I’m sure this will be buggy as I haven’t tested it, but I’ve done it before and it will make your pet follow the char. If you have any questions dont hesitate to ask me

1 Like

Thanks so much!! I will try this

Hi there, the post you marked as the solution doesnt work (just tested it). Try this instead ( Its a server script btw. and please please PLEASE make sure the primary part is unanchored, spent 20 minutes looking for why my script wasn’t working)

wait(2)
local char = -- Change this to the character
local pet = -- Change this to your pet
pet:PivotTo(char.HumanoidRootPart.CFrame)
local AO = Instance.new("AlignOrientation",pet)
local AP = Instance.new("AlignPosition",pet)
local A0 = Instance.new("Attachment",pet.PrimaryPart)
A0.Visible = false
local A1 = Instance.new("Attachment",char.HumanoidRootPart)
A1.Visible = false
A1.Position = Vector3.new(1,1,0) + pet.PrimaryPart.Size
AP.MaxForce = 25000
AP.MaxVelocity = 10
AP.Responsiveness = 25
AP.Attachment0 = A0
AP.Attachment1 = A1
AO.MaxTorque = 25000
AO.MaxAngularVelocity = 25
AO.Responsiveness = 25
AO.Attachment0 = A0
AO.Attachment1 = A1
pet.Parent = char
1 Like

Thank you for putting the time into writing that script for me!

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