Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --< Variables
- local Char = script.Parent.Parent
- local HPR = Char.HumanoidRootPart
- local Children = game.Workspace:GetChildren()
- local UIService = game:GetService("UserInputService")
- local Targets = nil
- local RunService = game:GetService("RunService")
- local Target = nil
- local TargetNum = nil
- local Camera = game.Workspace.CurrentCamera
- local Circle = script:WaitForChild("Circle")
- local Health = game.Players.LocalPlayer.PlayerGui:WaitForChild("Health")
- --< Functions
- local getTargetsInOrder = function()
- local Chars = {}
- --Find All Players
- for i, v in pairs(Children) do
- if v:FindFirstChild("HumanoidRootPart")and
- v:FindFirstChild("Humanoid") and
- v ~= Char then
- table.insert(Chars, v)
- end
- end
- --Order Characters from Close to Far
- local ReturnValue = {Chars[1]}
- local ClosestMag =
- (ReturnValue[1].HumanoidRootPart.Position -
- HPR.Position).magnitude
- table.remove(Chars, 1)
- for i, v in pairs(Chars) do
- local PlayerPos = HPR.Position
- local ThisPos = v.HumanoidRootPart.Position
- if (PlayerPos - ThisPos).magnitude < ClosestMag then
- table.insert(ReturnValue, 1, v)
- ClosestMag = (PlayerPos - ThisPos).magnitude
- else
- for a = #ReturnValue, 1, -1 do
- if (PlayerPos - ThisPos).magnitude >
- (ReturnValue[a].HumanoidRootPart.Position -
- PlayerPos).magnitude then
- table.insert(ReturnValue, a+1, v)
- break
- end
- end
- end
- end
- return ReturnValue, #Chars + 1
- end
- --< Event for new Input
- UIService.InputBegan:Connect(function(input, engine)
- if engine then return end
- if not HPR then return end
- if input.KeyCode == Enum.KeyCode.LeftShift then
- Target = getTargetsInOrder()[1]
- script.Parent.Target.Value = Target.Name
- script.Sound:Play()
- billboard = Target.Head:WaitForChild("BillboardGui")
- billboard.Enabled = true
- Health.Enabled = true
- TargetNum = 1
- Circle.Parent = Target.HumanoidRootPart
- Circle.Enabled = true
- local IsLocked = Instance.new("BoolValue")
- IsLocked.Name = "IsLocked"
- IsLocked.Parent = Char
- elseif input.KeyCode == Enum.KeyCode.E and Target then
- local _,Chars = getTargetsInOrder()
- TargetNum = (TargetNum + 1)
- if TargetNum > #getTargetsInOrder() then
- TargetNum = 1
- end
- Target = getTargetsInOrder()[TargetNum]
- Circle.Enabled = false
- billboard.Enabled = false
- print(TargetNum)
- Circle.Parent = Target.HumanoidRootPart
- Circle.Enabled = true
- billboard = Target.Head:FindFirstChild("BillboardGui")
- billboard.Enabled = true
- print(Target)
- elseif input.KeyCode == Enum.KeyCode.Q and Target then
- local _,Chars = getTargetsInOrder()
- TargetNum = (TargetNum - 1)
- if TargetNum < 1 then
- TargetNum = #getTargetsInOrder()
- print("THE NUMBER IS LESS THAN 1 SO ;-;")
- end
- Circle.Enabled = false
- billboard.Enabled = false
- print(TargetNum)
- Target = getTargetsInOrder()[TargetNum]
- Circle.Parent = Target.HumanoidRootPart
- Circle.Enabled = true
- billboard = Target.Head:FindFirstChild("BillboardGui")
- billboard.Enabled = true
- end
- end)
- UIService.InputEnded:Connect(function(input)
- if input.KeyCode == Enum.KeyCode.LeftShift then
- Target = nil
- TargetNum = nil
- script.Parent.Target.Value = ""
- billboard.Enabled = false
- Circle.Enabled = false
- Health.Enabled = false
- Char:WaitForChild("IsLocked"):destroy()
- end
- end)
- --< RenderStepped Event
- local l = 0
- RunService.RenderStepped:Connect(function()
- if Target and Target.Humanoid.Health > 0 then
- if (Target.HumanoidRootPart.Position - HPR.Position).magnitude > 15 then
- local TargetHRP = Target.HumanoidRootPart
- HPR.CFrame = CFrame.new(HPR.Position,TargetHRP.Position)
- local offset = Vector3.new(0,4,5)
- local camMag = (TargetHRP.Position - Camera.CFrame.p).magnitude
- local newCFrame = TargetHRP.Position + ((HPR.Position + offset)- TargetHRP.Position).Unit * ((HPR.Position - TargetHRP.Position).Magnitude + 12)
- local newFrame = CFrame.new(newCFrame,TargetHRP.Position)
- Camera.CameraType = Enum.CameraType.Scriptable
- Camera.CFrame = Camera.CFrame:Lerp(newFrame, l)
- l = l == 1 or l + 0.1 and 0.1
- else
- local TargetHRP = Target.HumanoidRootPart
- HPR.CFrame = CFrame.new(HPR.Position,TargetHRP.Position)
- Camera.CameraType = Enum.CameraType.Scriptable
- Camera.CFrame = Camera.CFrame:Lerp(HPR.CFrame * CFrame.new(-5,5,15), l)
- l = l == 1 or l + 0.1 and 0.1
- end
- else
- Camera.CameraType = Enum.CameraType.Custom
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement