I Cant Get My Pet Script Working

All the notes I have will be in the adjusted script below.



NewPet.CanCollide = false

local PetPos = Instance.new("BodyPosition", NewPet)

local PetGyro = Instance.new("BodyGyro", NewPet)

PetGyro.MaxTorque = Vector3.new(400000,400000,400000)

local Owner = 'Pigred72'

while wait(1) do --- Changed this to wait(1) for easier readability.
	
	local OwnerObj = workspace:WaitForChild(Owner)
	
	local OwnerPos = OwnerObj.HumanoidRootPart --- I removed .Position for it to be easier to use in the next line
	
	local StopAt = ((OwnerPos.Position - NewPet.Position).magnitude - 5) * 1000
	--- You used OwnerObj instead of OwnerPos, which is what I assuemd you meant.
	PetPos.P = StopAt
	
	PetPos.Position = OwnerPos.Position + OwnerPos.CFrame.lookVector * - 5
	--- Vector3.new(0, 10, 0) raises the part 10 studs up, instead of 5 studs behind...
    --- ... I replaced it with lookVector - 5, which is 5 studs behind the character.

	PetGyro.CFrame = OwnerObj.HumanoidRootPart.CFrame

end

I’ll also drop this topic about lookVectors so you understand a bit about the change I made!

1 Like