Advertisement
CriShoux

Untitled

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