
Key RequiredUniversal

local UIS = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local camera = workspace.CurrentCamera
local running = false
function Closestplr()
local closest = math.huge
local closestplr = nil
for i,v in pairs(Players:GetPlayers()) do
if v ~= player and v.team ~= player.team then
local distance = (player.Character.HumanoidRootPart.Position - v.Character.HumanoidRootPart.Position).magnitude
if distance < closest then
closest = distance
closestplr = v
end
end
end
return closestplr
end
UIS.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.KeyCode == Enum.KeyCode.MouseButton2 and not running then
running = true
while running do
task.wait()
local target = Closestplr()
if target and target.Character and target.Character:FindFirstChild("HumanoidRootPart") then
camera.CFrame = CFrame.new(camera.CFrame.Position, target.Character.HumanoidRootPart.Position)
end
end
end
end)
-- Detect when "E" is released
UIS.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.E then
running = false
end
end)No comments yet for this script.



