Advertisement
Freshbloodb

Untitled

Nov 29th, 2024
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2. local RunService = game:GetService("RunService")
  3.  
  4. local localPlayer = Players.LocalPlayer
  5. local character = localPlayer.Character or localPlayer.CharacterAdded:Wait()
  6. local humanoid = character:WaitForChild("Humanoid")
  7. local rootPart = character:WaitForChild("HumanoidRootPart")
  8.  
  9. local function hasItem()
  10. if character:FindFirstChildOfClass("Tool") then
  11. return true
  12. end
  13.  
  14. local backpack = localPlayer:FindFirstChild("Backpack")
  15. if backpack and #backpack:GetChildren() > 0 then
  16. return true
  17. end
  18.  
  19. return false
  20. end
  21.  
  22. local function getClosestPlayer()
  23. local closestPlayer = nil
  24. local shortestDistance = math.huge
  25.  
  26. for _, player in ipairs(Players:GetPlayers()) do
  27. if player ~= localPlayer and player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
  28. local humanoid = player.Character:FindFirstChild("Humanoid")
  29.  
  30. if humanoid and humanoid.Health > 0 then
  31. local distance = (rootPart.Position - player.Character.HumanoidRootPart.Position).Magnitude
  32. if distance < shortestDistance then
  33. shortestDistance = distance
  34. closestPlayer = player
  35. end
  36. end
  37. end
  38. end
  39.  
  40. return closestPlayer
  41. end
  42.  
  43. local function moveToPlayer(targetPlayer)
  44. if not targetPlayer or not targetPlayer.Character then
  45. return
  46. end
  47.  
  48. local targetPosition = targetPlayer.Character.HumanoidRootPart.Position
  49. humanoid:MoveTo(targetPosition)
  50. end
  51.  
  52. RunService.Heartbeat:Connect(function()
  53. -- Comprobar si EnablePerseguirUsuario está habilitado
  54. if _G.EnablePerseguirUsuario and hasItem() then
  55. local closestPlayer = getClosestPlayer()
  56. if closestPlayer then
  57. moveToPlayer(closestPlayer)
  58. end
  59. end
  60. end)
  61.  
  62. localPlayer.CharacterAdded:Connect(function(newCharacter)
  63. character = newCharacter
  64. humanoid = newCharacter:WaitForChild("Humanoid")
  65. rootPart = newCharacter:WaitForChild("HumanoidRootPart")
  66. end)
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement