Advertisement
nooblollolololol

ee

May 19th, 2024 (edited)
695
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.82 KB | Source Code | 0 0
  1. local Players = game:GetService("Players")
  2. local RunService = game:GetService("RunService")
  3. local UserInputService = game:GetService("UserInputService")
  4. local localPlayer = Players.LocalPlayer
  5.  
  6. local tpAuraEnabled = false
  7. local interval = 1
  8. local setBackTime = 0
  9.  
  10. local wasTpAuraEnabledBeforeDeath = false
  11.  
  12. local function isPlayerAlive(player)
  13.     if player.Character and player.Character:FindFirstChild("HumanoidRootPart") and player.Character:FindFirstChild("Humanoid") then
  14.         return player.Character.Humanoid.Health > 0
  15.     end
  16.     return false
  17. end
  18.  
  19. local function getNearestPlayer()
  20.     local nearestPlayer = nil
  21.     local shortestDistance = math.huge
  22.  
  23.     for _, player in pairs(Players:GetPlayers()) do
  24.         if player ~= localPlayer and isPlayerAlive(player) then
  25.             local distance = (localPlayer.Character.HumanoidRootPart.Position - player.Character.HumanoidRootPart.Position).Magnitude
  26.             if distance < shortestDistance then
  27.                 shortestDistance = distance
  28.                 nearestPlayer = player
  29.             end
  30.         end
  31.     end
  32.  
  33.     return nearestPlayer
  34. end
  35.  
  36. local function tpAura()
  37.     if not tpAuraEnabled or not isPlayerAlive(localPlayer) then return end
  38.  
  39.     local humanoidRootPart = localPlayer.Character:WaitForChild("HumanoidRootPart")
  40.     local savedPosition = humanoidRootPart.Position
  41.     local savedCFrame = humanoidRootPart.CFrame
  42.  
  43.     local nearestPlayer = getNearestPlayer()
  44.     if nearestPlayer and nearestPlayer.Character and nearestPlayer.Character:FindFirstChild("HumanoidRootPart") then
  45.         local targetPosition = nearestPlayer.Character.HumanoidRootPart.Position
  46.         local direction = (targetPosition - humanoidRootPart.Position).unit
  47.         local backPosition = targetPosition - direction * 2
  48.  
  49.         humanoidRootPart.CFrame = CFrame.new(backPosition, targetPosition)
  50.  
  51.         task.wait(setBackTime)
  52.  
  53.         humanoidRootPart.CFrame = savedCFrame
  54.     end
  55. end
  56.  
  57. local function toggleTpAura()
  58.     tpAuraEnabled = not tpAuraEnabled
  59.     if tpAuraEnabled then
  60.         while tpAuraEnabled and isPlayerAlive(localPlayer) do
  61.             tpAura()
  62.             task.wait(interval)
  63.         end
  64.     end
  65. end
  66.  
  67. local function onPlayerDied()
  68.     print("Player has died!")
  69.     wasTpAuraEnabledBeforeDeath = tpAuraEnabled
  70.     tpAuraEnabled = false
  71. end
  72.  
  73. local function onCharacterAdded(character)
  74.     print("Character added or respawned!")
  75.     local humanoid = character:WaitForChild("Humanoid")
  76.     local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
  77.  
  78.     humanoid.Died:Connect(onPlayerDied)
  79.  
  80.     task.wait(0.1)
  81.     if wasTpAuraEnabledBeforeDeath then
  82.         toggleTpAura()
  83.     end
  84. end
  85.  
  86. localPlayer.CharacterAdded:Connect(onCharacterAdded)
  87.  
  88. UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
  89.     if gameProcessedEvent then return end
  90.  
  91.     if input.KeyCode == Enum.KeyCode.M then
  92.         toggleTpAura()
  93.     end
  94. end)
  95.  
  96. if localPlayer.Character then
  97.     onCharacterAdded(localPlayer.Character)
  98. else
  99.     localPlayer.CharacterAdded:Wait()
  100. end
  101.  
Tags: iDK
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement