Advertisement
aesnike

INF DODGE

Oct 30th, 2024
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2. local RunService = game:GetService("RunService")
  3. local LocalPlayer = Players.LocalPlayer
  4.  
  5. -- Function to find the nearest NPC (as provided)
  6. local function findNearestNPC()
  7. local nearestNPC = nil
  8. local nearestDistance = math.huge
  9.  
  10. local Character = LocalPlayer.Character
  11. if not Character or not Character:FindFirstChild("HumanoidRootPart") then return end
  12.  
  13. local dungeon = workspace:FindFirstChild("dungeon")
  14. if not dungeon then return end
  15.  
  16. for _, child in ipairs(dungeon:GetChildren()) do
  17. if child:FindFirstChild("enemyFolder") then
  18. for _, npc in ipairs(child.enemyFolder:GetChildren()) do
  19. if npc:FindFirstChild("HumanoidRootPart") and npc:FindFirstChild("Humanoid") and npc.Humanoid.Health > 0 then
  20. local distance = (Character.HumanoidRootPart.Position - npc.HumanoidRootPart.Position).Magnitude
  21. if distance < nearestDistance then
  22. nearestDistance = distance
  23. nearestNPC = npc
  24. end
  25. end
  26. end
  27. end
  28. end
  29. return nearestNPC
  30. end
  31.  
  32. local function freezeCharacter(character)
  33. if character and character:FindFirstChild("HumanoidRootPart") then
  34. character.HumanoidRootPart.Anchored = true
  35. end
  36. end
  37.  
  38. local function teleportToNPC()
  39. local Character = LocalPlayer.Character
  40. if not Character or not Character:FindFirstChild("HumanoidRootPart") then return end
  41.  
  42. local npc = findNearestNPC()
  43. if npc and npc:FindFirstChild("HumanoidRootPart") then
  44. local npcPosition = npc.HumanoidRootPart.Position
  45. local teleportPosition = Vector3.new(npcPosition.X, npcPosition.Y + 12, npcPosition.Z)
  46.  
  47. -- Calculate the direction to face the NPC
  48. local lookVector = (npcPosition - teleportPosition).Unit
  49. local lookCFrame = CFrame.new(teleportPosition, teleportPosition + lookVector)
  50.  
  51. Character.HumanoidRootPart.CFrame = lookCFrame
  52. freezeCharacter(Character)
  53. end
  54. end
  55.  
  56. -- Main loop
  57. local function mainLoop()
  58. while true do
  59. teleportToNPC()
  60. wait(2) -- Wait for 2 seconds before the next teleportation
  61. end
  62. end
  63.  
  64. -- Function to setup character
  65. local function setupCharacter(character)
  66. character:WaitForChild("HumanoidRootPart")
  67. freezeCharacter(character)
  68. coroutine.wrap(mainLoop)()
  69. end
  70.  
  71. -- Initial setup
  72. if LocalPlayer.Character then
  73. setupCharacter(LocalPlayer.Character)
  74. end
  75.  
  76. -- Handle character respawns
  77. LocalPlayer.CharacterAdded:Connect(setupCharacter)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement