Pet follow player script

Hello, Developers.

I am trying to make a script so that a pet will follow a player. It works, but it is not smooth whatsoever. Here is my script:

`local rootpart = script.Parent.Parent.Parent:FindFirstChild("HumanoidRootPart")

local pet = script.Parent

while true do
wait()
local pos = rootpart.CFrame * CFrame.new(2,2,2)
script.Parent.Parent:SetPrimaryPartCFrame(pos)
end`

I have tried using BodyGyro and BodyPosition in the PrimaryPart, but it only has effect on the PrimaryPart.

Any suggestion is appreciated! :smile:

1 Like

Using BodyPositions is your best bet. Connecting the model together with welds will allow body movers to affect the entire model.

3 Likes

Thanks, I will try that.

Could you please explain further on “not smooth”

You should indent your code with 3 ` so that it is easier to read like so:

Screenshot_20190219-170517_Chrome

3 Likes

You’ll want to weld all all the parts inside your pet model together using Weld Attachments which can be found in the Model tab
image

After you’ve done that you’ll want to use a BodyPosition to move your Pet and a BodyGyro to keep it upright and facing the same direction as the Character.

Also hen pasting code, put it in a code block like below:

```lua

```

This makes it easier for others to read your code and help you. You can find the “`” to the left of your 1 key.

6 Likes