Please tell me what is wrong with my PET

After learning about body gyros and body positions at developer.Roblox.com, I wrote some code to give a player a pet and to my surprise it worked…then it didn’t. The pet does not move at all! I looked around online and found that my code was seemingly identical to other peoples. So I wondered, why is mine not working? I tried comparing my code with the other peoples but I found no difference. Please help!

local pet = script.Parent

function GivePet(player)
	if player then
		if player.Character then
			local Character = player.Character
			local humanoid = Character:WaitForChild("HumanoidRootPart")
			
			local newPet = pet:Clone()
			newPet.CanCollide = false
			newPet.BrickColor = BrickColor.new("Baby blue")
			newPet.Transparency = 0
			newPet.Parent = player.Character
			
			local bodyGyro = Instance.new("BodyGyro") 
			bodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
			
			local bodyPos = Instance.new("BodyPosition")
			bodyPos.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
			
			bodyGyro.Parent = newPet
			bodyPos.Parent = newPet
			
			while wait() do
				print("Moving...")
				bodyPos.Position = humanoid.Position + Vector3.new(2,2,3)
				bodyGyro.CFrame = player.character.HumanoidRootPart.CFrame	
			end
		end
	end	
end

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		GivePet(player)
	end)
end)

The pet is in the workspace and the code is in the pet.

there is nothing I can see wrong, but try lowering maxforce to say 1000000, also, what is wrong exactly?
does the pet just not spawn, not move, get teleported off screen, “then it didn’t” is kinda vague

Sorry about being vague. The pet does not move at all. I have tried adjusting values already.

well sorry but i dont actally see anything wrong, all i can think of is the pet is anchored

No, I believe it is not. :frowning:

ummm… I put the script inside a not anchored, cancollide on, part, and uh… Look:

so it works, maybe the problem is the pet MODEL

1 Like

BodyMovers won’t work on Anchored parts make sure that the Pet Model’s Descendants are not Anchored. Also creating a while loop each time a Player’s Character adds can cause performance issue its better to add all pets to a Table and loop through the table in a while loop outside the function.

Hello @Zompocolypse ,

So to fix it make your pet unanchored then try to make the pet parent to workspace.Another one is if you have a moving problem, then try to keep the body pos manually and a script for it to change its position.

And change this:

bodyGyro.CFrame = player.character.HumanoidRootPart.CFrame -- Its character make it to Character

And keep the script in server script service and keep the pet in replicated storage or server storage.

It was a cube part like yours. I do not understand why it did not work. I will check things out.

it has to have cancollide ON, anchored OFF