--[[==================================================
NAME DISPLAY + AIM LOCK SCRIPT (ALL-IN-ONE)
- Shows display name above players' heads
- Locks camera on nearest torso while holding RMB
==================================================]]
-- Services
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local RunService = game:GetService("RunService")
local UIS = game:GetService("UserInputService")
local Camera = workspace.CurrentCamera
local mouse = LocalPlayer:GetMouse()
-----------------------------------------------------
-- 1. NAME DISPLAY ABOVE HEAD
-----------------------------------------------------
local function addNameTag(character, plr)
local head = character:WaitForChild("Head", 5)
if not head then return end
local billboard = Instance.new("BillboardGui")
billboard.Parent = head
billboard.Adornee = head
billboard.Size = UDim2.new(0, 200, 0, 50)
billboard.StudsOffset = Vector3.new(0, 3.2, 0)
billboard.AlwaysOnTop = true
local nameLabel = Instance.new("TextLabel")
nameLabel.Parent = billboard
nameLabel.BackgroundTransparency = 1
nameLabel.AnchorPoint = Vector2.new(0.5, 0.5)
nameLabel.Position = UDim2.new(0.5, 0, 0.5, 0)
nameLabel.Text = plr.DisplayName
nameLabel.TextColor3 = Color3.new(1, 1, 1)
nameLabel.TextStrokeTransparency = 0.5
nameLabel.Font = Enum.Font.GothamBold
nameLabel.TextScaled = false
nameLabel.TextSize = 18
RunService.RenderStepped:Connect(function()
if head and head:IsDescendantOf(workspace) then
local distance = (Camera.CFrame.Position - head.Position).Magnitude
local size = math.clamp(30 - distance / 4, 10, 30)
nameLabel.TextSize = size
end
end)
end
local function onCharacterAdded(character, plr)
addNameTag(character, plr)
end
for _, plr in pairs(Players:GetPlayers()) do
if plr ~= LocalPlayer then
plr.CharacterAdded:Connect(function(char)
onCharacterAdded(char, plr)
end)
if plr.Character then
onCharacterAdded(plr.Character, plr)
end
end
end
Players.PlayerAdded:Connect(function(plr)
if plr ~= LocalPlayer then
plr.CharacterAdded:Connect(function(char)
onCharacterAdded(char, plr)
end)
end
end)
-----------------------------------------------------
-- 2. AIM LOCK (RIGHT MOUSE BUTTON)
-----------------------------------------------------
local holding = false
local lockedTarget = nil
-- Find closest player's torso (HumanoidRootPart) to your mouse
local function getClosestTorso()
local closest, shortest = nil, math.huge
for _, plr in pairs(Players:GetPlayers()) do
if plr ~= LocalPlayer and plr.Character and plr.Character:FindFirstChild("HumanoidRootPart") then
local torso = plr.Character.HumanoidRootPart
local pos, onScreen = Camera:WorldToViewportPoint(torso.Position)
if onScreen then
local dist = (Vector2.new(pos.X, pos.Y) - Vector2.new(mouse.X, mouse.Y)).Magnitude
if dist < shortest then
shortest = dist
closest = torso
end
end
end
end
return closest
end
-- Update camera to locked target
RunService.RenderStepped:Connect(function()
if holding and lockedTarget then
if lockedTarget.Parent and lockedTarget:IsDescendantOf(workspace) then
Camera.CFrame = CFrame.new(Camera.CFrame.Position, lockedTarget.Position)
else
lockedTarget = nil
end
end
end)
UIS.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton2 then
if not holding then
lockedTarget = getClosestTorso()
holding = true
end
end
end)
UIS.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton2 then
holding = false
lockedTarget = nil
end
end)