Pet System with Custom Character

Soo I am trying to make a pet follow the character but It doesn’t really work, here is the code I got, and do note that I got the code from another post: (Post: What is the best way to make a pet system? - #11 by deedubbleyew)

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Humanoid = Player:FindFirstChild("Humanoid")
local Hroot = Humanoid.HumanoidRootPart

local Pet = script.Pets.Test_Pet

local function SetPetCFrame()
	Pet.CFrame = Hroot.CFrame * CFrame.new(2, 2, -3)
end -- Hroot is player's HumanoidRootPart

game:GetService("RunService"):BindToRenderStep("SetPet", Enum.RenderPriority.Last, SetPetCFrame)

I don’t think HumanoidRootPart is a valid member of Humanoid.

HumanoidRootPart belongs to the character, not the humanoid.

So try this:

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local char = Player.Character or Player.CharacterAdded:Wait()
local Hroot = char.HumanoidRootPart

local Pet = script.Pets.Test_Pet

local function SetPetCFrame()
    Pet.CFrame = Hroot.CFrame * CFrame.new(2, 2, -3)
end -- Hroot is player's HumanoidRootPart

game:GetService("RunService"):BindToRenderStep("SetPet", Enum.RenderPriority.Last,     SetPetCFrame)

Here is an api reference for you on using the character!

1 Like

Change

local Hroot = Humanoid.HumanoidRootPart

into

local Hroot = Humanoid.Parent.HumanoidRootPart

And

local Humanoid = Player:FindFirstChild("Humanoid")

into

local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
1 Like

Soo your solution might of worked but its my fault that I put the pets folder into the script, and its nill and I got a new problem for that, and here is the code: (Sorry for being a pain)

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local char = Player.Character or Player.CharacterAdded:Wait()
local Hroot = char.HumanoidRootPart

local Pet_S = game.ReplicatedStorage.Pets.Test_Pet:Clone()
Pet_S.Parent = workspace or game.Workspace

local function SetPetCFrame()
    Pet_S.CFrame = Hroot.CFrame * CFrame.new(2, 2, -3)
end -- Hroot is player's HumanoidRootPart

game:GetService("RunService"):BindToRenderStep("SetPet", Enum.RenderPriority.Last,     SetPetCFrame)

So in other words it doesn’t find the pets?