local o=game:GetService("\087\111\114\107\115\112\097\099\101")local T=game:GetService("\080\108\097\121\101\114\115")local m=T.LocalPlayer local w=require(script:WaitForChild("\080\101\116\077\111\118\101\109\101\110\116"))local e=require(script:WaitForChild("\080\101\116\065\110\105\109\097\116\105\111\110"))local function C(T,C)if T==m.Character then w(T,C)end e(C)if T==m.Character then wait()C.Parent=o end end local function n(o)o.ChildAdded:Connect(function(T)if T.Name=="\080\101\116"then C(o,T)end end)local T=o:FindFirstChild("\080\101\116")if T then C(o,T)end end function PlayerAdded(o)o.CharacterAdded:Connect(n)if o.Character then n(o.Character)end end T.PlayerAdded:Connect(PlayerAdded)for o,T in pairs(T:GetPlayers())do(coroutine.wrap(function()PlayerAdded(T)end))()end
--[[
TheNexusAvenger

Initializes and controls the pets of the player.
--]]

local Workspace = game:GetService("Workspace")
local Players = game:GetService("Players")

local LocalPlayer = Players.LocalPlayer
local PetMovement = require(script:WaitForChild("PetMovement"))
local PetAnimation = require(script:WaitForChild("PetAnimation"))



--[[
Sets up a pet.
--]]
local function PetAdded(Character,Pet)
    --Set up the pet movement and animations.
    if Character == LocalPlayer.Character then
        PetMovement(Character,Pet)
    end
    PetAnimation(Pet)

    --Move the pet to Workspace. Parenting to the character
    --flinging when jumping when the pet is stuck.
    if Character == LocalPlayer.Character then
        wait()
        Pet.Parent = Workspace
    end
end

--[[
Sets up a character.
--]]
local function CharacterAdded(Character)
    --Set up pets being added.
    Character.ChildAdded:Connect(function(PetModel)
        if PetModel.Name == "Pet" then
            PetAdded(Character,PetModel)
        end
    end)

    --Set up the existing pet.
    local ExistingPet = Character:FindFirstChild("Pet")
    if ExistingPet then
        PetAdded(Character,ExistingPet)
    end
end

--[[
Sets up a player.
--]]
function PlayerAdded(Player)
    Player.CharacterAdded:Connect(CharacterAdded)
    if Player.Character then
        CharacterAdded(Player.Character)
    end
end



--Set up players.
Players.PlayerAdded:Connect(PlayerAdded)
for _,Player in pairs(Players:GetPlayers()) do
    coroutine.wrap(function()
        PlayerAdded(Player)
    end)()
end