BodyPosition Stops Working After Part.Position is Set

In my game, I have a character effect system, some of said effects are floating companions. The companions just float in the air beside the players. I accomplish this via BodyPosition instances. Players get teleported to the map, and the companion comes along to the player slowly, therefore I want the companion to teleport if the player is teleported.

After the position of the part is set, it is as though the BodyPosition does not exist at all. It doesn’t move smoothly at all, and remains suspended in the air, immobile. However, it does move whenever its position is manually set, whenever the target position approaches a distance further than 30 studs away.

Essentially the way it works, is if the desired part is more than 30 studs away from the target position, it teleports it there.

Here is the current code running within the script:

while Object.Value do
	local Head = Object.Parent.Parent:FindFirstChild("Head")
	local BodyPosition = Object.Value:FindFirstChild("BodyPosition")
	
	if Head and BodyPosition then
		local Target = (Head.CFrame * Library.CompanionOffset).p
		
		if (Target - Object.Value.Position).magnitude >= 30 then
			Object.Value.Position = Target
		end
		
		BodyPosition.Position = Target
	end
	
	RunService.RenderStepped:Wait()
end

Note: The Object.Value references the part I wish to move.

If you have had any similar experiences with BodyPositions, or have any general insight that could assist me, please reply below. Thank you for your time and for reading. Have a great day.

  • MattPrograms
1 Like

Hmm, is this in a local script or server script?

If it’s in a local script then yeah the pet will remain immobile as the client has no physical ownership on the pet if it’s far away. Solution should be to give network ownership to the client.

Otherwise, I believe the issue may have to deal with sleeping parts which Idk how to deal with.