Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local LocalPlayer = game.Players.LocalPlayer
- local mouse = LocalPlayer:GetMouse()
- local camera = game.Workspace.CurrentCamera
- local function closestplayer()
- local NearestPlayerOrDummy = nil
- local NearestDistance = math.huge
- for _, child in pairs(workspace:GetChildren()) do
- if child:FindFirstChild("Humanoid") and child.Humanoid.Health > 0 and child:FindFirstChild("Head") then
- local Distance = (child.Head.Position - LocalPlayer.Character.Head.Position).magnitude
- if Distance < NearestDistance then
- NearestDistance = Distance
- NearestPlayerOrDummy = child
- end
- end
- end
- return NearestPlayerOrDummy
- end
- local function aimAtNearestPlayer()
- local settings = {
- keybind = Enum.UserInputType.MouseButton2
- }
- local UIS = game:GetService("UserInputService")
- local aiming = false --- this toggle will make it so we lock on to the person when we press our keybind
- UIS.InputBegan:Connect(function(inp)
- if inp.UserInputType == settings.keybind then
- aiming = true
- end
- end)
- UIS.InputEnded:Connect(function(inp)
- if inp.UserInputType == settings.keybind then ---- when we stop pressing the keybind it would unlock off the player
- aiming = false
- end
- end)
- game:GetService("RunService").RenderStepped:Connect(function()
- if aiming then
- camera.CFrame = CFrame.new(camera.CFrame.Position,closestplayer().Character.Head.Position) -- locks into the HEAD
- end
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement