Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService("Players")
- local LocalPlayer = Players.LocalPlayer
- local RunService = game:GetService("RunService")
- local CHARACTER_TELEPORT_DISTANCE = _G.CHARACTER_TELEPORT_DISTANCE or 20
- local BOMB_TRANSFER_TIMEOUT = _G.BOMB_TRANSFER_TIMEOUT or 0.5
- local RE_TELEPORT_DELAY = _G.RE_TELEPORT_DELAY or 10
- local lastBombTransferTime = {}
- local lastTeleportTime = {}
- local function GetClosestPlayer()
- local Character = LocalPlayer.Character
- if not Character then return nil end
- local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
- if not HumanoidRootPart then return nil end
- local closestPlayer = nil
- local closestDistance = math.huge
- for _, player in ipairs(Players:GetPlayers()) do
- if player == LocalPlayer then continue end
- local targetCharacter = player.Character
- if not targetCharacter then continue end
- local targetHumanoid = targetCharacter:FindFirstChildOfClass("Humanoid")
- if not targetHumanoid or targetHumanoid.Health <= 0 then continue end
- local targetRootPart = targetCharacter:FindFirstChild("HumanoidRootPart")
- if not targetRootPart then continue end
- local distance = (HumanoidRootPart.Position - targetRootPart.Position).Magnitude
- if distance < closestDistance then
- closestDistance = distance
- closestPlayer = player
- end
- end
- return closestPlayer, closestDistance
- end
- local function CanTeleportToPlayer(player)
- local currentTime = tick()
- if lastTeleportTime[player.UserId] and currentTime - lastTeleportTime[player.UserId] < RE_TELEPORT_DELAY then
- return false
- end
- return true
- end
- local function TeleportToPlayer(targetPlayer)
- local Character = LocalPlayer.Character
- if not Character then return end
- local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
- if not HumanoidRootPart then return end
- local targetCharacter = targetPlayer.Character
- if not targetCharacter then return end
- local targetRootPart = targetCharacter:FindFirstChild("HumanoidRootPart")
- if not targetRootPart then return end
- local forwardPosition = targetRootPart.CFrame:PointToWorldSpace(Vector3.new(0, 0, -3))
- HumanoidRootPart.CFrame = CFrame.new(forwardPosition, targetRootPart.Position)
- local RightHand = Character:FindFirstChild("RightHand") or Character:FindFirstChild("Right Arm")
- if RightHand then
- RightHand.CFrame = targetRootPart.CFrame * CFrame.new(-1, 0, 0)
- end
- lastTeleportTime[targetPlayer.UserId] = tick()
- end
- local function TeleportCharacterToClosestPlayer()
- local Character = LocalPlayer.Character
- if not Character then return end
- local Bomb = Character:FindFirstChildOfClass("Tool")
- if not Bomb or Bomb.Name ~= "Bomb" then return end
- local closestPlayer, closestDistance = GetClosestPlayer()
- if not closestPlayer or closestDistance > CHARACTER_TELEPORT_DISTANCE then return end
- if not CanTeleportToPlayer(closestPlayer) then return end
- local currentTime = tick()
- if lastBombTransferTime[closestPlayer.UserId] and currentTime - lastBombTransferTime[closestPlayer.UserId] > BOMB_TRANSFER_TIMEOUT then
- print("Teletransportación cancelada: No se pasó la bomba a", closestPlayer.Name)
- lastTeleportTime[closestPlayer.UserId] = currentTime
- return
- end
- TeleportToPlayer(closestPlayer)
- if Bomb:FindFirstChild("Handle") then
- Bomb.Handle.CFrame = closestPlayer.Character.HumanoidRootPart.CFrame
- lastBombTransferTime[closestPlayer.UserId] = currentTime
- print("Bomba pasada a:", closestPlayer.Name)
- end
- end
- RunService.Heartbeat:Connect(function()
- if _G.EnableTeleportUser then
- TeleportCharacterToClosestPlayer()
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement