SHARE
TWEET

Untitled

a guest Apr 21st, 2019 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Shortening
  2. local char = game.Players.LocalPlayer.Character
  3. local camera = workspace.CurrentCamera
  4.  
  5. --Services
  6. local uis = game:GetService("UserInputService")
  7. local rs = game:GetService("RunService")
  8.  
  9. --Settings
  10. local shiftDown = false
  11. local lookingAtPart = false
  12. local point
  13.  
  14. --Input
  15. uis.InputBegan:Connect(function(io, gpe)
  16.     if io.KeyCode == Enum.KeyCode.LeftShift and not gpe then
  17.         shiftDown = true
  18.     end
  19. end)
  20. uis.InputEnded:Connect(function(io, gpe)
  21.     if io.KeyCode == Enum.KeyCode.LeftShift and not gpe then
  22.         shiftDown = false
  23.     end
  24. end)
  25.  
  26. --Lock on closest player
  27. local increment = 1
  28. rs.RenderStepped:Connect(function()
  29.     --Closest player
  30.     local plr
  31.     local otherPlayers = {}
  32.     for i,v in pairs(game.Players:GetPlayers()) do
  33.         if v.Character ~= char then
  34.             table.insert(otherPlayers, v)
  35.         end
  36.     end
  37.     if #otherPlayers > 1 then
  38.         for i,v in pairs(otherPlayers) do
  39.             if i == 1 then
  40.                 plr = v
  41.             else
  42.                 local currentDistance = (v.Character.Head.CFrame.Position - char.Head.CFrame.Position).Magnitude
  43.                 local pastDistance = (otherPlayers[i-1].Character.Head.CFrame.Position - char.Head.CFrame.Position).Magnitude
  44.                 if currentDistance > pastDistance then
  45.                     plr = v
  46.                 end
  47.             end
  48.         end
  49.     end
  50.     if plr then point = plr.Character.Head end
  51.    
  52.     if point then
  53.         --lookingAtPart
  54.         local part, hitPos = workspace:FindPartOnRay(Ray.new(camera.CFrame.Position, camera.CFrame.LookVector * 500), char)
  55.         if part == point then
  56.             lookingAtPart = true
  57.         else
  58.             lookingAtPart = false
  59.         end
  60.        
  61.         --Lerping
  62.         if shiftDown then
  63.             if increment < 101 and not lookingAtPart then
  64.                 camera.CFrame = camera.CFrame:Lerp(CFrame.new(camera.CFrame.Position, point.CFrame.Position), increment/100)
  65.                 increment = increment + 2
  66.             else
  67.                 camera.CFrame = CFrame.new(camera.CFrame.Position, point.CFrame.Position)
  68.             end
  69.         else
  70.             increment = 1
  71.         end
  72.     end
  73. end)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top