Certainly! Here's an updated version of the LocalScript that includes a box outline for the ESP and also displays the distance from the local player to each NPC. The box outline is created using a frame, and the distance is calculated and displayed below the NPC's name.
-- LocalScript
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Camera = workspace.CurrentCamera
-- Check Updating of NPC
local function updateESP()
-- Search for NPCs in the workspace
for _, npc in pairs(workspace.Npcs:GetChildren()) do
if npc:IsA("Model") and npc:FindFirstChild("HumanoidRootPart") then
local billboardGui = npc:FindFirstChild("ESP")
if not billboardGui then
-- Create a BillboardGui if it doesn't exist
billboardGui = Instance.new("BillboardGui")
billboardGui.Name = "ESP"
billboardGui.AlwaysOnTop = true
billboardGui.Size = UDim2.new(0, 200, 0, 100) -- Adjust size to include name and distance
billboardGui.StudsOffset = Vector3.new(0, 2, 0) -- Adjust as necessary
billboardGui.Parent = npc.HumanoidRootPart
-- Create Frame for box ESP
local frame = Instance.new("Frame")
frame.Size = UDim2.new(1, 0, 1, 0)
frame.BorderSizePixel = 2
frame.BackgroundTransparency = 1
frame.BorderColor3 = Color3.new(1, 0, 0) -- Red color for box
frame.Parent = billboardGui
-- Create a TextLabel for displaying the NPC's name
local nameLabel = Instance.new("TextLabel")
nameLabel.Size = UDim2.new(1, 0, 0.5, 0)
nameLabel.BackgroundTransparency = 1
nameLabel.TextColor3 = Color3.new(1, 1, 1) -- White color for text
nameLabel.Text = npc.Name
nameLabel.TextScaled = true
nameLabel.Parent = billboardGui
-- Create a TextLabel for displaying the distance
local distanceLabel = Instance.new("TextLabel")
distanceLabel.Size = UDim2.new(1, 0, 0.5, 0)
distanceLabel.Position = UDim2.new(0, 0, 0.5, 0)
distanceLabel.BackgroundTransparency = 1
distanceLabel.TextColor3 = Color3.new(1, 1, 0) -- Yellow color for distance
distanceLabel.TextScaled = true
distanceLabel.Parent = billboardGui
end
-- Update distance
local character = LocalPlayer.Character
if character and character:FindFirstChild("HumanoidRootPart") then
local distance = (character.HumanoidRootPart.Position - npc.HumanoidRootPart.Position).magnitude
billboardGui.TextLabel.Text = npc.Name
billboardGui.TextLabel.TextLabel.Text = string.format("Distance: %.0f", distance)
end
end
end
end
-- Use Rendering Stepped to Constantly Update the ESP
game:GetService("RunService").RenderStepped:Connect(updateESP)
Explanation:
-
Frame for Box ESP: I added a frame to act as an outline box for each NPC. It appears as a border with adjustable color and thickness.
-
Distance Calculation: The distance from the local player to each NPC is calculated using the .magnitude property of the vector difference between their positions. It's then displayed in a TextLabel positioned under the name label within the BillboardGui.
Remember:
- Double-check the hierarchy and make sure the NPCs are correctly organized under
Workspace.Npcs.
- Adjust the
StudsOffset, colors, and sizes according to your preferences for optimal appearance.
- Carefully test this script within the Roblox Studio to ensure it displays correctly and performs as expected.