I want to make a pet/Roblox Character that walks around and follows you!
The Output is saying:
Workspace:
While I do know what’s wrong I don’t know how to fix it, here is the script down below.
while true do
wait(0.1)
script.Parent.Humanoid:MoveTo(player.Character.HumanoidRootPart)
end
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
Your code looked nice overall, but I found just a few errors.
The reason you are getting the error you are, might be because the script is running before the Humanoid has loaded. To fix this, call WaitForChild() at the start of your script to wait for the Humanoid to load in.
Example:
local Humanoid = script.Parent:WaitForChild ("Humanoid")
Secondly, I’m not sure if you have more code in this Script than what you posted, but you have not defined the player yet. If you want it to follow your player character, you can store your character in a variable when you first Play the game.
Finnaly, you also need to set the MoveTo()'s parameter to the “Position” of the HumanoidRootPart, not the HumanoidRootPart object directly
Example:
local Character = workspace:WaitForChild ("your player name") --store your character as a variable
local Humanoid = script.Parent:WaitForChild ("Humanoid") --store the pet's Humanoid as a variable
while true do
wait(0.1)
Humanoid:MoveTo(Character:WaitForChild("HumanoidRootPart").Position) --Move the pet Model to the Position of the Character's HumanoidRootPart
end
Resources:
https://developer.roblox.com/en-us/api-reference/function/Humanoid/MoveTo
https://developer.roblox.com/en-us/api-reference/function/Instance/WaitForChild
2 Likes
I always used :MoveTo
on models, so im not sure if it works on Humanoid.
and to my knowledge :moveto()
doesnt rotate parts. example: pets
local chr = workspace:WaitForChild("your name")--waits for character
local hrp = chr:WaitForChild("HumanoidRootPart")--waits for HRP
while wait() do
local frame = hrp.CFrame + Vector3.new(0,5,0)--cframe local must be in a loop, otherwise it will be stuck at 1 pos
local bodyvel = Instance.new("BodyVelocity", script.Parent)--bodyvelocity to simulate that its somewhat "anchored"
bodyvel.Velocity = Vector3.new(0,0,0)
script.Parent.Parent:SetPrimaryPartCFrame((frame))--moving part to the position.
end
Also, :SetPrimaryPartCFrame((frame))
only works on models so you might have to do this:
Also to make sure, that the pet is rotated correctly - make sure that face in on the Front Side, which you can check by doing:
2 Likes
Instead of moving your pets Humanoid move it’s root part where everything is joined I’m guessing that is HumanoidRootPart.