Follow Nearest player
Key Required

Follow Nearest player

Brookhaven 🏡RPDizzilovellDizzilovell 9.3K views 10 executesUpdated Jul 21, 2025
5.0/ 5(1 votes)
10100% Positive
Lua Script•49 lines (1790 chars)
-- Follow nearest player by walking (Humanoid:MoveTo)
-- Delta Executor compatible

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local HRP = Character:WaitForChild("HumanoidRootPart")

local targetPlayer = nil

-- Function to find nearest player with humanoid root part
local function GetNearestPlayer()
    local nearest = nil
    local shortestDistance = math.huge
    for _, player in pairs(Players:GetPlayers()) do
        if player ~= LocalPlayer and player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
            local dist = (HRP.Position - player.Character.HumanoidRootPart.Position).Magnitude
            if dist < shortestDistance then
                shortestDistance = dist
                nearest = player
            end
        end
    end
    return nearest
end

-- Periodically update the target and move towards them
while true do
    -- Update character references in case of respawn
    Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
    Humanoid = Character:WaitForChild("Humanoid")
    HRP = Character:WaitForChild("HumanoidRootPart")
    
    targetPlayer = GetNearestPlayer()

    if targetPlayer and targetPlayer.Character and targetPlayer.Character:FindFirstChild("HumanoidRootPart") then
        local targetPos = targetPlayer.Character.HumanoidRootPart.Position
        -- Move to target's position
        Humanoid:MoveTo(targetPos)
    else
        -- No valid target, stop moving
        Humanoid:MoveTo(HRP.Position)
    end

    wait(0.5)  -- update every 0.5 seconds to avoid spamming
end

Features & Information

Follows the nearest player

Community Comments (0)

No comments yet for this script.

More Scripts for Brookhaven 🏡RP