local Players = game:GetService("Players") local RunService = game:GetService("RunService") local player = Players.LocalPlayer local character = player.Character or player.CharacterAdded:Wait() local humanoid, hrp -- Respawn handler local function onCharacterAdded(char) character = char humanoid = char:WaitForChild("Humanoid") hrp = char:WaitForChild("HumanoidRootPart") end player.CharacterAdded:Connect(onCharacterAdded) onCharacterAdded(character) -- Utility local function getEquippedTool() for _, tool in ipairs(character:GetChildren()) do if tool:IsA("Tool") then return tool end end return nil end local function faceTarget(targetHRP) local myPos = hrp.Position local targetPos = Vector3.new(targetHRP.Position.X, myPos.Y, targetHRP.Position.Z) hrp.CFrame = CFrame.new(myPos, targetPos) end local function getClosestPlayer(maxDistance) local closest, shortestDist = nil, maxDistance for _, other in ipairs(Players:GetPlayers()) do if other ~= player and other.Character and other.Character:FindFirstChild("HumanoidRootPart") then local dist = (other.Character.HumanoidRootPart.Position - hrp.Position).Magnitude if dist < shortestDist then closest = other shortestDist = dist end end end return closest, shortestDist end -- Main loop RunService.RenderStepped:Connect(function() if not humanoid or not hrp then return end local closestPlayer, rawDistance = getClosestPlayer(100) if not closestPlayer then return end local targetHRP = closestPlayer.Character and closestPlayer.Character:FindFirstChild("HumanoidRootPart") if not targetHRP then return end -- Calculate scaled thresholds based on velocity local myVelocity = hrp.Velocity.Magnitude local targetVelocity = targetHRP.Velocity.Magnitude local speed = math.max(myVelocity, targetVelocity) local scale = math.floor(speed / 10) local equipDist = 10 + scale local useDist = 8 + scale local unequipDist = 11 + scale local equippedTool = getEquippedTool() if rawDistance <= equipDist then if not equippedTool then humanoid:UnequipTools() task.wait(0.05) local tool = player.Backpack:FindFirstChildOfClass("Tool") if tool then humanoid:EquipTool(tool) end end -- Face and use tool faceTarget(targetHRP) if rawDistance <= useDist and getEquippedTool() then getEquippedTool():Activate() end elseif rawDistance >= unequipDist and equippedTool then humanoid:UnequipTools() end end)