Advertisement
xpa1nx0

Sword Burst 3 Script

Feb 29th, 2024
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2. local UserInputService = game:GetService("UserInputService")
  3. local Workspace = game:GetService("Workspace")
  4. local LocalPlayer = Players.LocalPlayer
  5.  
  6. local teleportEnabled = false
  7.  
  8. local function teleportPlayerBehind(enemy)
  9. local enemyRootPart = enemy:FindFirstChild("HumanoidRootPart")
  10. local playerCharacter = LocalPlayer.Character
  11.  
  12. if enemyRootPart and playerCharacter then
  13. local playerRootPart = playerCharacter:FindFirstChild("HumanoidRootPart")
  14. if playerRootPart then
  15. local newPosition = enemyRootPart.Position - (enemyRootPart.CFrame.LookVector * 5)
  16. playerRootPart.CFrame = CFrame.new(newPosition)
  17. end
  18. end
  19. end
  20.  
  21. local function getClosestEnemy()
  22. local closestEnemy = nil
  23. local closestDistance = math.huge
  24.  
  25. for _, descendant in pairs(Workspace.Mobs:GetDescendants()) do
  26. if descendant:IsA("Model") and descendant:FindFirstChild("HumanoidRootPart") then
  27. local enemyPart = descendant:FindFirstChild("HumanoidRootPart")
  28. local distance = (LocalPlayer.Character.HumanoidRootPart.Position - enemyPart.Position).magnitude
  29.  
  30. if distance < closestDistance then
  31. closestEnemy = descendant
  32. closestDistance = distance
  33. end
  34. end
  35. end
  36.  
  37. return closestEnemy
  38. end
  39.  
  40. local function onKeyPress(input, gameProcessed)
  41. if not gameProcessed then
  42. if input.UserInputType == Enum.UserInputType.Keyboard and input.KeyCode == Enum.KeyCode.T then
  43. teleportEnabled = not teleportEnabled
  44. print("Teleport Enabled: ", teleportEnabled) -- Debug print
  45. end
  46. end
  47. end
  48.  
  49. UserInputService.InputBegan:Connect(onKeyPress)
  50.  
  51. local function continuousTeleport()
  52. while task.wait() do
  53. if teleportEnabled then
  54. local closestEnemy = getClosestEnemy()
  55. if closestEnemy then
  56. teleportPlayerBehind(closestEnemy)
  57. end
  58. end
  59. end
  60. end
  61.  
  62. coroutine.wrap(continuousTeleport)()
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement