The following script will make the part face towards and move towards the nearest player. This uses body objects so you will need to have the following descendants under the part you want to move.
Part
local part = script.Parent
function move(target)
local dir = (target.Position - part.Position).unit
local spawnPos = part.Position
local pos = spawnPos + (dir * 1)
local speed = 15
part:findFirstChild("BodyGyro").cframe = CFrame.new(pos, pos + dir)
part:findFirstChild("BodyGyro").maxTorque = Vector3.new(10000,10000,10000)
part:findFirstChild("BodyPosition").position = target.Position
part:findFirstChild("BodyPosition").maxForce = Vector3.new(10000, 10000, 10000) * speed
end
function findNearestTorso(pos)
local list = game.Workspace:GetChildren()
local torso = nil
local dist = 50
local temp = nil
local human = nil
local temp2 = nil
for x = 1, #list do
temp2 = list[x]
if (temp2.className == "Model") and (temp2 ~= part) then
temp = temp2:findFirstChild("Torso")
human = temp2:findFirstChild("Humanoid")
if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
if (temp.Position - pos).magnitude < dist then
torso = temp
dist = (temp.Position - pos).magnitude
end
end
end
end
return torso
end
while true do
local torso = findNearestTorso(part.Position)
if torso ~= nil then
move(torso)
end
wait()
end
Note: This will keep pushing the player with a lot of force, I suggest adding a debounce that changes when the torso is touched. It will also fly upwards, but this is adjustable by changing the axes involved on the body position's maxForce on line 11.