Advertisement
Freshbloodb

Untitled

Nov 29th, 2024
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.85 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2. local LocalPlayer = Players.LocalPlayer
  3. local RunService = game:GetService("RunService")
  4.  
  5. local CHARACTER_TELEPORT_DISTANCE = _G.CHARACTER_TELEPORT_DISTANCE or 20
  6. local BOMB_TRANSFER_TIMEOUT = _G.BOMB_TRANSFER_TIMEOUT or 0.5
  7. local RE_TELEPORT_DELAY = _G.RE_TELEPORT_DELAY or 10
  8.  
  9. local lastBombTransferTime = {}
  10. local lastTeleportTime = {}
  11.  
  12. local function GetClosestPlayer()
  13. local Character = LocalPlayer.Character
  14. if not Character then return nil end
  15.  
  16. local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
  17. if not HumanoidRootPart then return nil end
  18.  
  19. local closestPlayer = nil
  20. local closestDistance = math.huge
  21.  
  22. for _, player in ipairs(Players:GetPlayers()) do
  23. if player == LocalPlayer then continue end
  24.  
  25. local targetCharacter = player.Character
  26. if not targetCharacter then continue end
  27.  
  28. local targetHumanoid = targetCharacter:FindFirstChildOfClass("Humanoid")
  29. if not targetHumanoid or targetHumanoid.Health <= 0 then continue end
  30.  
  31. local targetRootPart = targetCharacter:FindFirstChild("HumanoidRootPart")
  32. if not targetRootPart then continue end
  33.  
  34. local distance = (HumanoidRootPart.Position - targetRootPart.Position).Magnitude
  35. if distance < closestDistance then
  36. closestDistance = distance
  37. closestPlayer = player
  38. end
  39. end
  40.  
  41. return closestPlayer, closestDistance
  42. end
  43.  
  44. local function CanTeleportToPlayer(player)
  45. local currentTime = tick()
  46. if lastTeleportTime[player.UserId] and currentTime - lastTeleportTime[player.UserId] < RE_TELEPORT_DELAY then
  47. return false
  48. end
  49. return true
  50. end
  51.  
  52. local function TeleportToPlayer(targetPlayer)
  53. local Character = LocalPlayer.Character
  54. if not Character then return end
  55.  
  56. local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
  57. if not HumanoidRootPart then return end
  58.  
  59. local targetCharacter = targetPlayer.Character
  60. if not targetCharacter then return end
  61.  
  62. local targetRootPart = targetCharacter:FindFirstChild("HumanoidRootPart")
  63. if not targetRootPart then return end
  64.  
  65. local forwardPosition = targetRootPart.CFrame:PointToWorldSpace(Vector3.new(0, 0, -3))
  66. HumanoidRootPart.CFrame = CFrame.new(forwardPosition, targetRootPart.Position)
  67.  
  68. local RightHand = Character:FindFirstChild("RightHand") or Character:FindFirstChild("Right Arm")
  69. if RightHand then
  70. RightHand.CFrame = targetRootPart.CFrame * CFrame.new(-1, 0, 0)
  71. end
  72.  
  73. lastTeleportTime[targetPlayer.UserId] = tick()
  74. end
  75.  
  76. local function TeleportCharacterToClosestPlayer()
  77. local Character = LocalPlayer.Character
  78. if not Character then return end
  79.  
  80. local Bomb = Character:FindFirstChildOfClass("Tool")
  81. if not Bomb or Bomb.Name ~= "Bomb" then return end
  82.  
  83. local closestPlayer, closestDistance = GetClosestPlayer()
  84. if not closestPlayer or closestDistance > CHARACTER_TELEPORT_DISTANCE then return end
  85.  
  86. if not CanTeleportToPlayer(closestPlayer) then return end
  87.  
  88. local currentTime = tick()
  89.  
  90. if lastBombTransferTime[closestPlayer.UserId] and currentTime - lastBombTransferTime[closestPlayer.UserId] > BOMB_TRANSFER_TIMEOUT then
  91. print("Teletransportación cancelada: No se pasó la bomba a", closestPlayer.Name)
  92. lastTeleportTime[closestPlayer.UserId] = currentTime
  93. return
  94. end
  95.  
  96. TeleportToPlayer(closestPlayer)
  97.  
  98. if Bomb:FindFirstChild("Handle") then
  99. Bomb.Handle.CFrame = closestPlayer.Character.HumanoidRootPart.CFrame
  100. lastBombTransferTime[closestPlayer.UserId] = currentTime
  101. print("Bomba pasada a:", closestPlayer.Name)
  102. end
  103. end
  104.  
  105. RunService.Heartbeat:Connect(function()
  106. if _G.EnableTeleportUser then
  107. TeleportCharacterToClosestPlayer()
  108. end
  109. end)
  110.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement