Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local player = game.Players.LocalPlayer
- local character = player.Character or player.CharacterAdded:Wait()
- local localroot = character:WaitForChild("HumanoidRootPart")
- local headCam = character:WaitForChild("Head")
- local ts = game:GetService("TweenService")
- local Cam = workspace.CurrentCamera
- local function closest()
- local target = nil
- local range = math.huge
- for _, v in pairs(game.Players:GetPlayers()) do
- if v ~= player and v.Character then
- local JN = v.Character:FindFirstChild("HumanoidRootPart")
- if JN then
- local dist = (localroot.Position - JN.Position).magnitude
- if dist < range then
- range = dist
- target = v
- end
- end
- end
- end
- return target
- end
- local function Non_Behind_Wall_Target()
- local t = closest()
- if t and t.Character then
- local vroot = t.Character:FindFirstChild("HumanoidRootPart")
- local vhumanoid = t.Character:FindFirstChildOfClass("Humanoid")
- if vroot and vhumanoid and vhumanoid.Health > 0 then
- local direction = (vroot.Position - headCam.Position).unit * 1000
- local Ray_setting = RaycastParams.new()
- Ray_setting.FilterDescendantsInstances = {character}
- Ray_setting.FilterType = Enum.RaycastFilterType.Blacklist
- local result = workspace:Raycast(headCam.Position, direction, Ray_setting)
- if result and result.Instance:IsDescendantOf(t.Character) then
- return vroot
- end
- end
- end
- return nil
- end
- while wait() do
- local t = Non_Behind_Wall_Target()
- if t then
- local tween = ts:Create(Cam, TweenInfo.new(0.25), {CFrame = CFrame.new(Cam.CFrame.Position, t.Position)})
- tween:Play()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement