How would I make a part smoothly follow the player?

i’ve tried doing the other stuff people did in other topics, but they didn’t work for me
i’ve done my own thing and it works, but it’s choppy and the part looks like its “teleporting” at very high speeds.

local function getNearestPlayer()
		local nearestPlayer = nil
		local nearestDistance = math.huge

		for _, player in pairs(players:GetPlayers()) do
			if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
				local playerPos = player.Character.HumanoidRootPart.Position
				local ballPos = Orb.primarypart.Position
				local distance = (playerPos - ballPos).Magnitude

				if distance < nearestDistance then
					nearestPlayer = player
					nearestDistance = distance
				end
			end
		end
		
		return nearestPlayer
	end
local function track()
		createForce()
		Event = game:GetService("RunService").Heartbeat:Connect(function()
			if chasePlayerPause then
				coroutine.yield()
			else
				local nearestPlayer = getNearestPlayer()
				if nearestPlayer then
					Orb.primarypart.CFrame = CFrame.lookAt(Orb.primarypart.Position, Vector3.new(nearestPlayer.Character.PrimaryPart.Position.X, Orb.primarypart.Position.Y, nearestPlayer.Character.PrimaryPart.Position.Z))
					force.Force = Orb.primarypart.CFrame.LookVector * 200000
				end
			end
		end)
	end

how would i make the movement smoother without sacrificing ping due to the amount of signals being sent?

1 Like

200,000 force. what is the mass of the orb? even if it is mass 1000, it will travel at 200 studs/sec which is REALLY fast. so nothing can save it from looking like teleport. Are you sure it is the speed you want?

yeah, it’s welded to a bunch of parts which makes its mass skyrocket so i really have to crank up the force
it’s not as fast as it seems, and its in an enclosed area
if you want the exact mass, it’s 36426.42578125

oh okay it’s about 5 studs/sec. btw you can use BodyVelocity to set it to the speed you desired in case it is more about speed than force. or set https://create.roblox.com/docs/reference/engine/classes/BasePart#AssemblyLinearVelocity

also because it will run every Heartbeat, you can return if chasePlayerPause

Event = game:GetService("RunService").Heartbeat:Connect(function()
			if chasePlayerPause then return end
			local nearestPlayer = getNearestPlayer()
			if not nearestPlayer then return end
			Orb.primarypart.CFrame = CFrame.lookAt(Orb.primarypart.Position, Vector3.new(nearestPlayer.Character.PrimaryPart.Position.X, Orb.primarypart.Position.Y, nearestPlayer.Character.PrimaryPart.Position.Z))
			force.Force = Orb.primarypart.CFrame.LookVector * 200000
		end)

You can make a script that will just set the CFrame of the part to the CFrame of whatever you want it to follow, but use lerp. This will make it smoother

Here is an example.

while true do
	workspace.Part.CFrame = workspace.Part.CFrame:Lerp(script.Parent.HumanoidRootPart.CFrame, 0.025) -- The 0.025 is how fast the object will move to my player. The lower it is, the slower it takes, the higher it is, the faster it takes.
	task.wait()
end

Another way you could do this is by using an align position, or use a vector force object

use game:GetService("RunService").Stepped:Connect(function() it has a little delay allowing for smooth movements