Advertisement
SigmaBoy456

hookmetamethod example #852

Sep 5th, 2024
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. local player = game.Players.LocalPlayer
  2. local character = player.Character
  3. local localroot = character:WaitForChild("HumanoidRootPart")
  4.  
  5. local function closest()
  6. local range = math.huge
  7. local target = nil
  8. for _, v in pairs(game.Players:GetPlayers()) do
  9. if v ~= player and v.Team ~= player.Team and v.Character then
  10. local JN = v.Character:FindFirstChild("HumanoidRootPart")
  11. if JN then
  12. local dist = (localroot.Position - JN.Position).magnitude
  13. if dist < range then
  14. range = dist
  15. target = JN
  16. end
  17. end
  18. end
  19. end
  20. return target
  21. end
  22.  
  23. local remote = game:GetService("Players").LocalPlayer.Character.Revolver.RevolverScript.ClientLeftDown
  24. local t = closest()
  25.  
  26. local namecall
  27. namecall = hookmetamethod(game, "__namecall", function(self, ...)
  28. local args = {...}
  29. local method = getnamecallmethod()
  30. if not checkcaller() and self == remote and method:lower() == "fireserver" and t then
  31. args[1] = t.Position
  32. return namecall(self, unpack(args))
  33. end
  34. return namecall(self, ...)
  35. end)
  36.  
  37. game:GetService("RunService").Heartbeat:Connect(function()
  38. t = closest()
  39. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement