Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService("Players")
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local RunService = game:GetService("RunService")
- local LocalPlayer = Players.LocalPlayer
- local stepped = RunService.Stepped
- local heartbeat = RunService.Heartbeat
- local renderStepped = RunService.RenderStepped
- local GC = collectgarbage
- -- Hooking for faster function handling
- hookfunction(task.wait, function() return stepped:Wait() end)
- hookfunction(delay, function(_, f) task.spawn(f) end)
- hookfunction(spawn, function(f) task.spawn(f) end)
- -- Anti-lag utilities (optimized)
- local function safeGcCollect()
- local status, err = pcall(function()
- GC("collect")
- end)
- if not status then
- warn("Garbage collection failed: " .. err)
- end
- end
- local function cleanupInstance(inst)
- if inst and inst.Parent then
- inst:Destroy()
- end
- end
- -- Tool Logging Functions (Optimized)
- local function onToolEquipped(player, tool)
- print("[] " .. player.Name .. " equipped: " .. tool.Name)
- end
- local function watchTool(tool, player)
- if tool:IsA("Tool") then
- tool.Equipped:Connect(function()
- onToolEquipped(player, tool)
- end)
- end
- end
- local function handleTools(player)
- local function scan(container)
- for _, item in pairs(container:GetChildren()) do
- watchTool(item, player)
- end
- container.ChildAdded:Connect(function(child)
- watchTool(child, player)
- end)
- end
- if player.Character then
- scan(player.Character)
- end
- if player:FindFirstChild("Backpack") then
- scan(player.Backpack)
- end
- player.CharacterAdded:Connect(function(char)
- scan(char)
- end)
- end
- handleTools(LocalPlayer)
- -- Faster respawn handler without lag (optimized)
- local Respawning = false
- local DeathCount = 0
- local MaxDeathsBeforeEscape = 1
- local EscapeDelay = 0
- local LastDeathTime = 0
- local currentConnection = nil
- local function FastRespawn()
- spawn(function()
- while true do
- local character = LocalPlayer.Character
- local humanoid = character and character:FindFirstChildWhichIsA("Humanoid")
- if humanoid then
- -- Disconnect any previous event to prevent leaks
- if currentConnection then
- currentConnection:Disconnect()
- currentConnection = nil
- end
- if not Respawning then
- Respawning = true
- currentConnection = humanoid.Died:Connect(function()
- -- Reset Respawning flag immediately
- Respawning = true
- local now = tick()
- if now - LastDeathTime < EscapeDelay then
- DeathCount = DeathCount + 1
- else
- DeathCount = 0
- end
- LastDeathTime = now
- -- Quick escape logic
- if DeathCount >= MaxDeathsBeforeEscape then
- local escapePart = Instance.new("Part")
- escapePart.Size = Vector3.new(1, 1, 1)
- escapePart.CFrame = (LocalPlayer.Character and LocalPlayer.Character:FindFirstChild("HumanoidRootPart")
- and LocalPlayer.Character.HumanoidRootPart.CFrame) or CFrame.new()
- escapePart.Anchored = true
- escapePart.CanCollide = false
- escapePart.Transparency = 1
- escapePart.Parent = workspace
- task.wait(0) -- no delay, just yield frame
- cleanupInstance(escapePart)
- DeathCount = 0
- end
- -- Fire respawn guide quickly
- local guide = ReplicatedStorage:FindFirstChild("Guide")
- if guide then
- guide:FireServer()
- end
- Respawning = false
- safeGcCollect()
- end)
- end
- break
- end
- stepped:Wait()
- end
- end)
- end
- -- Call on respawn or character add
- LocalPlayer.CharacterAdded:Connect(function()
- Respawning = false
- FastRespawn()
- end)
- if LocalPlayer.Character then
- Respawning = false
- FastRespawn()
- end
- -- Efficient FPS management, avoiding unnecessary infinite loops
- task.spawn(function()
- while true do
- renderStepped:Wait()
- end
- end)
- task.spawn(function()
- while true do
- heartbeat:Wait()
- end
- end)
- task.spawn(function()
- while true do
- stepped:Wait()
- end
- end)
- -- Kill loop optimized (no lag)
- task.spawn(function()
- while true do
- for _, plr in pairs(Players:GetPlayers()) do
- if plr ~= LocalPlayer and plr.Character and plr.Character:FindFirstChild("Humanoid") then
- plr.Character.Humanoid.Health = 0
- end
- end
- stepped:Wait() -- Delay to prevent unnecessary CPU usage
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement