First, you should improve your existing code by:
-not updating the max force every heartbeat
-assigning a variable to math.huge (just for cleanleaness)
-indenting it
-grouping code together
local infinitevector = vector3.new(math.huge,math.huge,math.huge)
bp.MaxForce = infinitevector
gyro.MaxTorque = infinitevector
game:GetService("RunService").Heartbeat:connect(function()
bp.Position = part.Position
bp.D = 700
bp.P = 15000
gyro.D = 100
gyro.CFrame = part.CFrame
end)
Second (probably useless), If it’s a humanoid, you’re better off using MoveTo() instead of body gyros.
someHumanoid:MoveTo(vector3.new(0,0,0)) --makes the humanoid move to the world's 0,0,0 position. can be used on players too!
Third, if you want less lag, the client needs to do it. You need to setup a remoteEvent in replicatedstorage for communication, and some kind of script to tell the server where to lead the humanoid. You also need to make sure the desired position isn’t too far away from the player on the server, and to make sure the traffic resulting from this isn’t too extreme.
local lastOffset --for checking position, mentioned below
while wait(0.5) do --0.5 seconds is good enough, i guess?
local currentOffset --your offset, whatever you're using
if currentOffset ~= lastOffset then --we're making sure we're not passing pointless arguments
someRemoteEvent:Fire(currentOffset) --we fire to a remote event
lastOffset = currentOffset --sorry for the indenting, this is edited in
end
end
Now, we need to adapt the server to this.
theSameEventFromBefore.OnServerEvent:Connect(function(player,target) --may have errors
local playerPosition = player.Character.HumanoidRootPart.Position --for checking if the player wants to move the NPC too far away from themselves, eg. when they're exploiting
local magnitude = (playerPosition - target).Magnitude --distance between desired position and player position
if not magnitude > 10 then --whatever you would see fit for something like this is okay (10 is just an example)
--update the part position or something
end
end)
Please don’t paste this literal code into your script. it needs changes for your specific use case, as i have no clue what you are using for position.