Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Shortening
- local char = game.Players.LocalPlayer.Character
- local camera = workspace.CurrentCamera
- --Services
- local uis = game:GetService("UserInputService")
- local rs = game:GetService("RunService")
- --Settings
- local shiftDown = false
- local lookingAtPart = false
- local point
- --Input
- uis.InputBegan:Connect(function(io, gpe)
- if io.KeyCode == Enum.KeyCode.LeftShift and not gpe then
- shiftDown = true
- end
- end)
- uis.InputEnded:Connect(function(io, gpe)
- if io.KeyCode == Enum.KeyCode.LeftShift and not gpe then
- shiftDown = false
- end
- end)
- --Lock on closest player
- local increment = 1
- rs.RenderStepped:Connect(function()
- --Closest player
- local plr
- local otherPlayers = {}
- for i,v in pairs(game.Players:GetPlayers()) do
- if v.Character ~= char then
- table.insert(otherPlayers, v)
- end
- end
- for i,v in pairs(otherPlayers) do
- local currentDistance = (v.Character.Head.CFrame.Position - char.Head.CFrame.Position).Magnitude
- local pastDistance = (otherPlayers[i-1].Character.Head.CFrame.Position - char.Head.CFrame.Position).Magnitude
- if i == 1 then
- plr = v
- elseif currentDistance > pastDistance then
- plr = v
- end
- end
- if plr then point = plr.Character.Head end
- if point then
- --lookingAtPart
- local part, hitPos = workspace:FindPartOnRay(Ray.new(camera.CFrame.Position, camera.CFrame.LookVector * 500), char)
- if part == point then
- lookingAtPart = true
- else
- lookingAtPart = false
- end
- --Lerping
- if shiftDown then
- if increment < 101 and not lookingAtPart then
- camera.CFrame = camera.CFrame:Lerp(CFrame.new(camera.CFrame.Position, point.CFrame.Position), increment/100)
- increment = increment + 2
- else
- camera.CFrame = CFrame.new(camera.CFrame.Position, point.CFrame.Position)
- end
- else
- increment = 1
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement