Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. weapon = nil
  2. murder = false
  3. directmurder = false
  4. mouse = game.Players.LocalPlayer:GetMouse()
  5.  
  6. function GetNearestNPCToMouse()
  7. local PLAYERS = {}
  8. local PLAYER_HOLD = {}
  9. local DISTANCES = {}
  10. for i, v in pairs(game.Workspace.Enemies:GetChildren()) do
  11. if v ~= game.Players.LocalPlayer then
  12. table.insert(PLAYERS, v)
  13. end
  14. end
  15. for i, v in pairs(PLAYERS) do
  16. if v.HumanoidRootPart ~= nil then
  17. local AIM = v:FindFirstChild("HumanoidRootPart")
  18. if AIM ~= nil then
  19. local DISTANCE = (v:FindFirstChild("HumanoidRootPart").Position - game.Workspace.CurrentCamera.CFrame.p).magnitude
  20. local RAY = Ray.new(game.Workspace.CurrentCamera.CFrame.p, (mouse.Hit.p - game.Workspace.CurrentCamera.CFrame.p).unit * DISTANCE)
  21. local HIT,POS = game.Workspace:FindPartOnRay(RAY, game.Workspace)
  22. local DIFF = math.floor((POS - AIM.Position).magnitude)
  23. PLAYER_HOLD[v.Name .. i] = {}
  24. PLAYER_HOLD[v.Name .. i].dist= DISTANCE
  25. PLAYER_HOLD[v.Name .. i].plr = v
  26. PLAYER_HOLD[v.Name .. i].diff = DIFF
  27. table.insert(DISTANCES, DIFF)
  28. end
  29. end
  30. end
  31.  
  32. if unpack(DISTANCES) == nil then
  33. return nil
  34. end
  35.  
  36. local L_DISTANCE = math.floor(math.min(unpack(DISTANCES)))
  37. if L_DISTANCE > 20 then
  38. return nil
  39. end
  40.  
  41. for i, v in pairs(PLAYER_HOLD) do
  42. if v.diff == L_DISTANCE then
  43. return v.plr
  44. end
  45. end
  46. return nil
  47. end
  48.  
  49. mouse.KeyDown:Connect(function(key)
  50. if key == "r" then
  51. murder = true
  52. end
  53. end)
  54. mouse.KeyUp:Connect(function(key)
  55. if key == "r" then
  56. murder = false
  57. end
  58. end)
  59.  
  60. mouse.KeyDown:Connect(function(key)
  61. if key == "f" then
  62. murderdirect = true
  63. end
  64. end)
  65. mouse.KeyUp:Connect(function(key)
  66. if key == "f" then
  67. murderdirect = false
  68. end
  69. end)
  70.  
  71. for i,v in pairs(game.Players.LocalPlayer.Character:GetChildren()) do
  72. if v:IsA("Model") and v:FindFirstChild("Handle") then
  73. weapon = v
  74. end
  75. end
  76.  
  77.  
  78. game:GetService('RunService').Stepped:connect(function()
  79. if murder == true then
  80. for i, v in pairs(game.Workspace.Enemies:GetChildren()) do
  81. if v:FindFirstChild("Humanoid") then
  82. game:GetService("ReplicatedStorage").Modules.Network.RemoteEvent:FireServer("WeaponDamage", ""..weapon.Name.."", v.Humanoid)
  83. end
  84. end
  85. end
  86. if murderdirect == true then
  87. for i, v in pairs(game.Workspace.Enemies:GetChildren()) do
  88. if v:FindFirstChild("Humanoid") then
  89. local NPC = GetNearestNPCToMouse()
  90. game:GetService("ReplicatedStorage").Modules.Network.RemoteEvent:FireServer("WeaponDamage", ""..weapon.Name.."", NPC.Humanoid)
  91. end
  92. end
  93. end
  94. end)
  95.  
  96.  
  97. -- Hold R to kill all the NPCs around you
  98. -- Hold F to kill the closest NPC to your mouse
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement