Advertisement
Azzz_4565

Untitled

Jun 23rd, 2025
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.31 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  3. local RunService = game:GetService("RunService")
  4. local LocalPlayer = Players.LocalPlayer
  5. local stepped = RunService.Stepped
  6. local heartbeat = RunService.Heartbeat
  7. local renderStepped = RunService.RenderStepped
  8. local GC = collectgarbage
  9.  
  10. -- Hooking for faster function handling
  11. hookfunction(task.wait, function() return stepped:Wait() end)
  12. hookfunction(delay, function(_, f) task.spawn(f) end)
  13. hookfunction(spawn, function(f) task.spawn(f) end)
  14.  
  15. -- Anti-lag utilities (optimized)
  16. local function safeGcCollect()
  17.     local status, err = pcall(function()
  18.         GC("collect")
  19.     end)
  20.     if not status then
  21.         warn("Garbage collection failed: " .. err)
  22.     end
  23. end
  24.  
  25. local function cleanupInstance(inst)
  26.     if inst and inst.Parent then
  27.         inst:Destroy()
  28.     end
  29. end
  30.  
  31. -- Tool Logging Functions (Optimized)
  32. local function onToolEquipped(player, tool)
  33.     print("[] " .. player.Name .. " equipped: " .. tool.Name)
  34. end
  35.  
  36. local function watchTool(tool, player)
  37.     if tool:IsA("Tool") then
  38.         tool.Equipped:Connect(function()
  39.             onToolEquipped(player, tool)
  40.         end)
  41.     end
  42. end
  43.  
  44. local function handleTools(player)
  45.     local function scan(container)
  46.         for _, item in pairs(container:GetChildren()) do
  47.             watchTool(item, player)
  48.         end
  49.         container.ChildAdded:Connect(function(child)
  50.             watchTool(child, player)
  51.         end)
  52.     end
  53.  
  54.     if player.Character then
  55.         scan(player.Character)
  56.     end
  57.     if player:FindFirstChild("Backpack") then
  58.         scan(player.Backpack)
  59.     end
  60.  
  61.     player.CharacterAdded:Connect(function(char)
  62.         scan(char)
  63.     end)
  64. end
  65.  
  66. handleTools(LocalPlayer)
  67.  
  68. -- Faster respawn handler without lag (optimized)
  69. local Respawning = false
  70. local DeathCount = 0
  71. local MaxDeathsBeforeEscape = 1
  72. local EscapeDelay = 0
  73. local LastDeathTime = 0
  74.  
  75. local currentConnection = nil
  76.  
  77. local function FastRespawn()
  78.     spawn(function()
  79.         while true do
  80.             local character = LocalPlayer.Character
  81.             local humanoid = character and character:FindFirstChildWhichIsA("Humanoid")
  82.  
  83.             if humanoid then
  84.                 -- Disconnect any previous event to prevent leaks
  85.                 if currentConnection then
  86.                     currentConnection:Disconnect()
  87.                     currentConnection = nil
  88.                 end
  89.  
  90.                 if not Respawning then
  91.                     Respawning = true
  92.                     currentConnection = humanoid.Died:Connect(function()
  93.                         -- Reset Respawning flag immediately
  94.                         Respawning = true
  95.  
  96.                         local now = tick()
  97.                         if now - LastDeathTime < EscapeDelay then
  98.                             DeathCount = DeathCount + 1
  99.                         else
  100.                             DeathCount = 0
  101.                         end
  102.                         LastDeathTime = now
  103.  
  104.                         -- Quick escape logic
  105.                         if DeathCount >= MaxDeathsBeforeEscape then
  106.                             local escapePart = Instance.new("Part")
  107.                             escapePart.Size = Vector3.new(1, 1, 1)
  108.                             escapePart.CFrame = (LocalPlayer.Character and LocalPlayer.Character:FindFirstChild("HumanoidRootPart")
  109.                                 and LocalPlayer.Character.HumanoidRootPart.CFrame) or CFrame.new()
  110.                             escapePart.Anchored = true
  111.                             escapePart.CanCollide = false
  112.                             escapePart.Transparency = 1
  113.                             escapePart.Parent = workspace
  114.  
  115.                             task.wait(0) -- no delay, just yield frame
  116.                             cleanupInstance(escapePart)
  117.                             DeathCount = 0
  118.                         end
  119.  
  120.                         -- Fire respawn guide quickly
  121.                         local guide = ReplicatedStorage:FindFirstChild("Guide")
  122.                         if guide then
  123.                             guide:FireServer()
  124.                         end
  125.  
  126.                         Respawning = false
  127.                         safeGcCollect()
  128.                     end)
  129.                 end
  130.                 break
  131.             end
  132.             stepped:Wait()
  133.         end
  134.     end)
  135. end
  136.  
  137. -- Call on respawn or character add
  138. LocalPlayer.CharacterAdded:Connect(function()
  139.     Respawning = false
  140.     FastRespawn()
  141. end)
  142.  
  143. if LocalPlayer.Character then
  144.     Respawning = false
  145.     FastRespawn()
  146. end
  147.  
  148. -- Efficient FPS management, avoiding unnecessary infinite loops
  149. task.spawn(function()
  150.     while true do
  151.         renderStepped:Wait()
  152.     end
  153. end)
  154.  
  155. task.spawn(function()
  156.     while true do
  157.         heartbeat:Wait()
  158.     end
  159. end)
  160.  
  161. task.spawn(function()
  162.     while true do
  163.         stepped:Wait()
  164.     end
  165. end)
  166.  
  167. -- Kill loop optimized (no lag)
  168. task.spawn(function()
  169.     while true do
  170.         for _, plr in pairs(Players:GetPlayers()) do
  171.             if plr ~= LocalPlayer and plr.Character and plr.Character:FindFirstChild("Humanoid") then
  172.                 plr.Character.Humanoid.Health = 0
  173.             end
  174.         end
  175.         stepped:Wait() -- Delay to prevent unnecessary CPU usage
  176.     end
  177. end)
  178.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement