UnderCoverScripts

All of us are dead

Oct 13th, 2022 (edited)
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. local EnemiesFolder = workspace.Enemies
  2. local Players = game:GetService("Players")
  3. local Player = Players.LocalPlayer
  4. local Mouse = Player:GetMouse()
  5. local RunService = game:GetService("RunService")
  6.  
  7. local GetClosestToCursor = function()
  8. local closestDistance = math.huge
  9. local closestEnemy = nil
  10.  
  11. for _, enemy in pairs(EnemiesFolder:GetChildren()) do
  12. if not enemy:FindFirstChild("Head") then continue end
  13. if not enemy:FindFirstChildOfClass("Humanoid") then continue end
  14. if enemy.Humanoid.Health <= 0 then continue end
  15.  
  16. local screenPos, visible = workspace.CurrentCamera:WorldToViewportPoint(enemy.Head.Position)
  17.  
  18. if not visible then continue end
  19.  
  20. local distance = (Vector2.new(Mouse.X, Mouse.Y) - Vector2.new(screenPos.X, screenPos.Y)).Magnitude
  21. if distance < closestDistance then
  22. closestEnemy = enemy
  23. closestDistance = distance
  24. end
  25. end
  26.  
  27. return closestEnemy
  28. end
  29.  
  30. local ClosestEnemy = GetClosestToCursor()
  31. RunService.Stepped:Connect(function(time, deltaTime)
  32. ClosestEnemy = GetClosestToCursor()
  33. end)
  34.  
  35.  
  36. local old; old = hookmetamethod(game, '__namecall', function(this, ...)
  37. local args = {...}
  38. local method = getnamecallmethod()
  39.  
  40. if not checkcaller() and method == 'FireServer' and this.Name == "WeaponHit" then
  41. if ClosestEnemy then
  42. args[2].part = ClosestEnemy.Head
  43. end
  44. end
  45.  
  46. return old(this, unpack(args))
  47. end)
Add Comment
Please, Sign In to add comment