local o=.5 local T=5 local m=50 local w=game:GetService("\084\119\101\101\110\083\101\114\118\105\099\101")return function(e,C)local n=e:WaitForChild("\072\117\109\097\110\111\105\100")local y=e:WaitForChild("\072\117\109\097\110\111\105\100\082\111\111\116\080\097\114\116")local N=C:WaitForChild("\072\117\109\097\110\111\105\100")local I=C:WaitForChild("\072\117\109\097\110\111\105\100\082\111\111\116\080\097\114\116")local v local d=0;(coroutine.wrap(function()while C.Parent and n.Health>0 do local e=y.CFrame*CFrame.new(3,-1,0)local n=(e.Position-I.Position).magnitude if n>=m and tick()-d>.5 then I.CFrame=e d=tick()for o,T in pairs(C:GetDescendants())do if T:IsA("\066\097\115\101\080\097\114\116")then T.Transparency=T.Transparency+1;(w:Create(T,TweenInfo.new(.5),{Transparency=T.Transparency-1})):Play()end end elseif n>=T then N:MoveTo(e.Position)end if N:GetState()==Enum.HumanoidStateType.Running and(I.Velocity.magnitude<N.WalkSpeed/2 and n>=T)then if not v then v=tick()elseif tick()-v>o then N.Jump=true v=nil end else v=nil end wait()end end))()end
--[[
TheNexusAvenger

Manages the movement of pets.
--]]

local JUMP_AFTER_STUCK_DELAY = 0.5
local MIN_DISTANCE_TO_MOVE = 5
local MAX_DISTANCE_TO_TELEPORT = 50

local TweenService = game:GetService("TweenService")



return function (CharacterModel,PetModel)
    --Get the character and pet components.
    local CharacterHumanoid = CharacterModel:WaitForChild("Humanoid")
    local CharacterHumanoidRootPart = CharacterModel:WaitForChild("HumanoidRootPart")
    local PetHumanoid = PetModel:WaitForChild("Humanoid")
    local PetHumanoidRootPart = PetModel:WaitForChild("HumanoidRootPart")

    --Set up moving the pet.
    local LastJumpStart
    local LastTeleport = 0
    coroutine.wrap(function()
        while PetModel.Parent and CharacterHumanoid.Health > 0 do
            --Determine the target CFrame and distance.
            local TargetCFrame = CharacterHumanoidRootPart.CFrame * CFrame.new(3,-1,0)
            local PetDistance = (TargetCFrame.Position - PetHumanoidRootPart.Position).magnitude

            --Move the pet.
            if PetDistance >= MAX_DISTANCE_TO_TELEPORT and tick() - LastTeleport > 0.5 then
                PetHumanoidRootPart.CFrame = TargetCFrame

                --Display an animation for teleporting the pet.
                LastTeleport = tick()
                for _,Part in pairs(PetModel:GetDescendants()) do
                    if Part:IsA("BasePart") then
                        Part.Transparency = Part.Transparency + 1
                        TweenService:Create(Part,TweenInfo.new(0.5),{
                            Transparency = Part.Transparency - 1,
                        }):Play()
                    end
                end
            elseif PetDistance >= MIN_DISTANCE_TO_MOVE then
                PetHumanoid:MoveTo(TargetCFrame.Position)
            end

            --Jump the pet after a few seconds of being stuck.
            if PetHumanoid:GetState() == Enum.HumanoidStateType.Running and PetHumanoidRootPart.Velocity.magnitude < PetHumanoid.WalkSpeed/2 and PetDistance >= MIN_DISTANCE_TO_MOVE then
                if not LastJumpStart then
                    LastJumpStart = tick()
                elseif tick() - LastJumpStart > JUMP_AFTER_STUCK_DELAY then
                    PetHumanoid.Jump = true
                    LastJumpStart = nil
                end
            else
                LastJumpStart = nil
            end

            --Wait before updating.
            wait()
        end
    end)()
end