Advertisement
CriShoux

knife abilities cursor

Oct 5th, 2019
12,397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 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(x, y)
  6. local closestPlayer = nil
  7. local shortestDistance = math.huge
  8.  
  9. for i, v in pairs(game:GetService("Players"):GetPlayers()) do
  10. if v ~= localPlayer and v.Character and v.Character:FindFirstChild("Humanoid") and v.Character.Humanoid.Health ~= 0 and v.Character:FindFirstChild("HumanoidRootPart") and v.Character:FindFirstChild("Head") then
  11. local pos = currentCamera:WorldToViewportPoint(v.Character.HumanoidRootPart.Position)
  12. local magnitude = (Vector2.new(pos.X, pos.Y) - Vector2.new(x, 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 oldIndex = mt.__index
  26. if setreadonly then setreadonly(mt, false) else make_writeable(mt, true) end
  27. local newClose = newcclosure or function(f) return f end
  28.  
  29. mt.__index = newClose(function(t, k)
  30. if not checkcaller() and t == mouse and tostring(k) == "X" and string.find(getfenv(2).script.Name, "Client") and getClosestPlayerToCursor() then
  31. local closest = getClosestPlayerToCursor(oldIndex(t, k), oldIndex(t, "Y")).Character.Head
  32. local pos = currentCamera:WorldToScreenPoint(closest.Position)
  33. return pos.X
  34. end
  35. if not checkcaller() and t == mouse and tostring(k) == "Y" and string.find(getfenv(2).script.Name, "Client") and getClosestPlayerToCursor() then
  36. local closest = getClosestPlayerToCursor(oldIndex(t, "X"), oldIndex(t, k)).Character.Head
  37. local pos = currentCamera:WorldToScreenPoint(closest.Position)
  38. return pos.Y
  39. end
  40. if t == mouse and tostring(k) == "Hit" and string.find(getfenv(2).script.Name, "Client") and getClosestPlayerToCursor() then
  41. return getClosestPlayerToCursor(mouse.X, mouse.Y).Character.Head.CFrame
  42. end
  43.  
  44. return oldIndex(t, k)
  45. end)
  46.  
  47. if setreadonly then setreadonly(mt, true) else make_writeable(mt, false) end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement