Advertisement
CriShoux

apocalyptic attack

Oct 8th, 2019
860
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. local localPlayer = game:GetService("Players").LocalPlayer
  2. local currentCamera = game:GetService("Workspace").CurrentCamera
  3. local mouse = localPlayer:GetMouse()
  4.  
  5. local function getClosestPlayerToCursor()
  6. local closestPlayer = nil
  7. local shortestDistance = math.huge
  8.  
  9. for i, v in pairs(game:GetService("Workspace").enemies:GetChildren()) do
  10. if v:FindFirstChild("Humanoid") and v.Humanoid.Health ~= 0 and v:FindFirstChild("HumanoidRootPart") and v:FindFirstChild("Head") then
  11. local pos = currentCamera:WorldToViewportPoint(v.HumanoidRootPart.Position)
  12. local magnitude = (Vector2.new(pos.X, pos.Y) - Vector2.new(mouse.X, mouse.Y)).magnitude
  13.  
  14. if magnitude < shortestDistance then
  15. closestPlayer = v
  16. shortestDistance = magnitude
  17. end
  18. end
  19. end
  20.  
  21. return closestPlayer
  22. end
  23.  
  24. local mt = getrawmetatable(game)
  25. local oldNamecall = mt.__namecall
  26. if setreadonly then setreadonly(mt, false) else make_writeable(mt, true) end
  27. local namecallMethod = getnamecallmethod or get_namecall_method
  28. local newClose = newcclosure or function(f) return f end
  29.  
  30. mt.__namecall = newClose(function(...)
  31. local method = namecallMethod()
  32. local args = {...}
  33.  
  34. if tostring(method) == "FireServer" and tostring(args[1]) == "Gun" and getClosestPlayerToCursor() then
  35. args[2]["Hit"] = getClosestPlayerToCursor().Head
  36. args[2]["Pos"] = getClosestPlayerToCursor().Head.Position
  37.  
  38. return oldNamecall(unpack(args))
  39. end
  40.  
  41. return oldNamecall(...)
  42. end)
  43.  
  44. if setreadonly then setreadonly(mt, true) else make_writeable(mt, false) end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement