How to fix a pet that follows you?

Your code looked nice overall, but I found just a few errors.

The reason you are getting the error you are, might be because the script is running before the Humanoid has loaded. To fix this, call WaitForChild() at the start of your script to wait for the Humanoid to load in.
Example:

local Humanoid = script.Parent:WaitForChild ("Humanoid")

Secondly, I’m not sure if you have more code in this Script than what you posted, but you have not defined the player yet. If you want it to follow your player character, you can store your character in a variable when you first Play the game.

Finnaly, you also need to set the MoveTo()'s parameter to the “Position” of the HumanoidRootPart, not the HumanoidRootPart object directly

Example:

local Character = workspace:WaitForChild ("your player name") --store your character as a variable
local Humanoid = script.Parent:WaitForChild ("Humanoid") --store the pet's Humanoid as a variable
while true do
	wait(0.1)
    Humanoid:MoveTo(Character:WaitForChild("HumanoidRootPart").Position) --Move the pet Model to the Position of the Character's HumanoidRootPart
end
Resources:

https://developer.roblox.com/en-us/api-reference/function/Humanoid/MoveTo

https://developer.roblox.com/en-us/api-reference/function/Instance/WaitForChild

2 Likes