Working on pet following script, giving me error

so i’m trying to make a simple pet script, where the pet follows the player when the player equips the pet

well i tried to run the script and it gave me this error


this is the code without the error:

i dont really know what to do here because it worked perfectly fine for the tutorial i was watching

i am a beginner so please bare with me

Your error is that BodyGyro doesn’t have a member MaxForce, rather MaxTorque.

Replace bg.MaxForce with bg.MaxTorque.

Also, please don’t use the deprecated BodyGyro and BodyPosition and use their replacements AlignOrientation and AlignPosition. Your tutorial is outdated! :grin:

If you have questions about AlignOrientation and AlignPosition, dont hesitate to reply.

first of all, instead of sharing screenshots you can use the Preformatted text or

code block

using one backtick, for preformatted text or three backticks for

a code block

you can also just press the button that looks like this: </>
this helps us…

Now, regarding the pet, use humanoids;
don’t use forces or whatever.

here is a script using a humanoid and pathfindingservice, to find the path to the player, it doesn’t cover cases where the path gets blocked but yeah.

local Humanoid = --your humanoid here, you only need this for your npc to be alive, but 
--you don't need it in your script
local root = --your model's root part here.

local ps = game:GetService("PathfindingService")
local path = ps:CreatePath()--empty path

path:ComputeAsync(root.Position, --add the player's pos here..;)
for _, waypoint in ipairs(path:GetWaypoints()) do
  if waypoint.Action == Enum.PathWaypointAction.Jump then
    humanoid.Jump = true--make the humanoid jump
 end
 humanoid:MoveTo(waypoint.Position) --force the npc to move to the waypoint's position
end

this is a simple example and will obviously only run once and also, fail if the path is not found.
but this is just to tell you why not to use forces, and use npcs and humanoids, because roblox provides lots of support for them, for following etc.

here is the documentation to humanoid & pathfinding:Humanoid | Documentation - Roblox Creator Hub
pathfinding: PathfindingService | Documentation - Roblox Creator Hub
PathWaypoint | Documentation - Roblox Creator Hub

thank you, I made those changes, but now it is telling me that position is not a valid member of AlignPosition

1 Like

It is correct. position doesn’t exist, but Position (capital P), does exist!

1 Like

thank you for all this, the code runs without giving any errors, but it still doesn’t work. Do you suggest i find a different script or i try to make this one work?

I don’t think forces are the way to go, as @scavengingbot mentioned. You should look into roblox’s pathfinding service instead. I do think the fix to your current code, however, is setting bg.MaxTorque to just math.huge instead of a Vector3, and bp.MaxForce to math.huge aswell for the same reason.

this tutorial might help

it shows how to make the pet you want

you need to use tool then script it by using Equipped event
Hope this will help you :smile:
Edit: if this tutorial didnt help you try to search on browser and on youtube tutorials

thank you for this tutorial, but it isnt working perfectly. I did everything in the tutorial, but when i test it the pet seems so follow me, but doesn’t continously follow me

code:

local pet = script.Parent

function givepet(player)
	if player then
		local character = player.Character
		if character then
			local humanrootpart = character.HumanoidRootPart
			local newpet = pet:Clone()
			newpet.Parent = character
			
			local bodyPos = Instance.new("BodyPosition", newpet)
			bodyPos.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
			
			local bodyGyro = Instance.new("BodyGyro", newpet)
			bodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
			
			while wait() do
				bodyPos.Position = humanrootpart.Position + Vector3.new(3,1,3)
				bodyGyro.CFrame = humanrootpart.CFrame
			end
		end
	end
end

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		givepet(player)
	end)
end)

video:

try this tutorial