Advertisement
SigmaBoy456

Roblox Universal Player Lock Script

Sep 14th, 2024 (edited)
902
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. local setting = {
  2. KeyToActive = Enum.KeyCode.K,
  3. TurnDeg = 15,
  4. KeyToTurnOff = Enum.KeyCode.P,
  5. range = 30
  6. }
  7.  
  8. local player = game.Players.LocalPlayer
  9. local character = player.Character
  10. local localroot = character:WaitForChild("HumanoidRootPart")
  11. local UIS = game:GetService("UserInputService")
  12.  
  13. local function closest()
  14. local target = nil
  15. for i, v in pairs(game.Players:GetPlayers()) do
  16. if v ~= player and v.Character then
  17. local KJ = v.Character:FindFirstChild("HumanoidRootPart")
  18. if KJ then
  19. local dist = (localroot.Position - KJ.Position).magnitude
  20. if dist < setting.range then
  21. target = v.Character
  22. end
  23. end
  24. end
  25. end
  26. return target
  27. end
  28.  
  29. local newtarget = closest()
  30. game:GetService("RunService").RenderStepped:Connect(function()
  31. newtarget = closest()
  32. end)
  33.  
  34. local active = false
  35.  
  36. local function ActiveScript()
  37. if active == true and newtarget then
  38. local JN = newtarget:FindFirstChild("HumanoidRootPart")
  39. local JNR = newtarget:FindFirstChildOfClass("Humanoid")
  40. local distTwo = (localroot.Position - JN.Position).magnitude
  41. if JN and JNR and JNR.Health > 0 then
  42. while active and distTwo < setting.range and JNR.Health > 0 do
  43. game:GetService("RunService").RenderStepped:Wait()
  44. if distTwo < setting.range then
  45. localroot.CFrame = CFrame.lookAt(localroot.Position, JN.Position) * CFrame.Angles(0, math.rad(setting.TurnDeg), 0)
  46. distTwo = (localroot.Position - JN.Position).magnitude
  47. end
  48. end
  49. end
  50. end
  51. end
  52.  
  53. UIS.InputBegan:Connect(function(input)
  54. if input.KeyCode == setting.KeyToActive then
  55. active = true
  56. elseif input.KeyCode == setting.KeyToTurnOff then
  57. active = false
  58. end
  59. end)
  60.  
  61. game:GetService("RunService").RenderStepped:Connect(function()
  62. ActiveScript()
  63. end)
  64.  
  65. game.Players.LocalPlayer.CharacterAdded:Connect(function(char)
  66. wait(1)
  67. character = char
  68. localroot = character:WaitForChild("HumanoidRootPart")
  69. wait(0.1)
  70. ActiveScript()
  71. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement